Forecasting and visualization R
I set a polynomial for my data and visualized the results. I am trying to expand my plot to the future and predict the value of x (date) when y is less than 70. My data is replicated HERE . My current code is below.
data <- read.table("data.txt", sep="\t", header=T)
data$date<- as.Date(data$date)
data$y <- as.numeric(data$y)
attach(data)
x <- 1:88 # vector for formula coordinates. I haven't found a way to plot polynomial formula with dates..
p <- qplot(date, y, data=data , geom="line", xlab="Time", ylab="y")
p+ geom_smooth(method = "lm", formula = y ~ poly(x, 3))
fit <- lm(y~poly(x,3))
summary(fit) #Fit is adequate
What are the results of this graph:
The third order polynomial was made with a numeric vector x because I didn't know how to use dates as "coordinates" for the formula. I would like to predict, that is, extend this graph to the future and find out at which date y is below 70 using this formula.
+3
source to share
No one has answered this question yet
Check out similar questions: