[R] predicting values into the future

Felipe Carrillo mazatlanmexico at yahoo.com
Mon Apr 6 05:08:04 CEST 2009


Thank you Bill and Gabor:
I do have a few years of fish sizes data (from larvae to juvenile). If I melt them together how can I create the best model to predict future weights. My weeks go up to 16 right now, but I want to predict weights for week 17 to 20. Based on both of you examples it was easy to fit a model with one year but I can't figure out how to create a model with all the years together.See the data below:

mydf <- read.table(textConnection("first second third fourth fifth sixth seventh
0.08 0.003 0.1 0.003 0.003 0.003 0.002
0.3 0.11 0.6 0.06 0.13 0.02 0.12
1.78 0.33 2.1 0.26 0.69 0.23 0.34
2.91 0.63 4 0.76 1.51 0.87 1.08
4.4 1.51 6.2 1.63 2.57 1.27 1.91
5.5 2.34 8.17 2.49 3.2 2.65 2.8
6.69 3.3 9.64 3.6 5 3.91 4.17
7.8 5 12.1 5.5 6.2 4.9 5.2
9.1 6.2 15 7 7.7 6.3 6.7
10.6 7.7 16.5 8.5 9.2 7.8 8.2
12.1 9.2 18 10 11.6 9.4 9.7
13.6 12.2 19.5 12.9 13.3 10.9 11.2
16.8 13.7 22.2 14.4 15 12.9 13.2
18 15.7 23.7 15.9 16 13.9 14.2
20 16.7 26 16.9 16 17.2 17.9
21 18 27.2 18.1 17 18.3 19.1"),header=T)
mydf
mydf$week <- 1:16
mydf <- melt(mydf)
colnames(mydf) <- c('week','year','weights')
attach(mydf)




> 
> * With such a short series, you don't stand much chance
> of fitting a time series model such as with arima.  It's
> clearly not stationary, too.  If you had multiple growth
> curves you may stand some chance of fitting a correlated
> model, but with just one, I don't think so.  For now, I
> think you just may have to make the hopeful assumption of
> independence.
> 
> You might like to look at this.
> 
> ________________________________
> 
> weightData <- data.frame(weight =
> c(2.1,2.4,2.8,3.6,4.1,5.2,6.3),
>                          week = 1:7)
> 
> plot(weight ~ week, weightData)
> plot(log(weight) ~ week, weightData)
> 
> ### clearly the log plot seems to linearise things.  
> ### Try an non-linear regression:
> 
> wModel <- nls(weight ~ alpha + beta*exp(gamma*week),
> weightData,
>               start = c(alpha = 0.0, beta = 1, gamma =
> 0.2), trace = TRUE)
> 
> #### you should look at the residuals from this to see if
> the assumptions
> #### look reasonable.  With only 7, you can't see much,
> though.
> 
> #### now suppose you want to predict for another 3 weeks:
> 
> newData <- data.frame(week = 1:10)
> newData$pweight <- predict(wModel, newData)
> 
> plot(pweight ~ week, newData, pch = 4, col =
> "red", ylab = "Weight", xlab =
> "Week")
> with(weightData, points(week, weight))
> 
> #### looks OK to me (thought fish cannot keep on growing
> exponentailly
> #### forever - this is clearly a model with limitations and
> you have to
> #### be careful when pushing it too far).
> 
> #### finally predict on a more continuous scale and add in
> the result as
> #### a blue line.
> 
> lData <- data.frame(week = seq(1, 10, len = 1000))
> with(lData, lines(week, predict(wModel, lData), col =
> "blue"))
> 
> #### Now that we have over-analysed this miniscule data set
> to blazes,
> #### perhaps it's time for a beer!
> 
> __________________________________
>   
> Bill Venables
> http://www.cmis.csiro.au/bill.venables/ 
 
> Hi:
> I have usually used the GROWTH() excel function to do this
> but now want to see if I can do this with R.
> I want to predict values into the future, possibly with the
> predict.arima Function. 
> I have the following weekly fish weight averages:
> 
> weight <-
> c("2.1","2.4","2.8","3.6","4.1","5.2","6.3")
> week   <-
> c("1","2","3","4","5","6","7")
> 
> I would like to predict what the weight will be by week 10
> based on my weight values and make a line plot of all the
> weights(including the predicted values). I have two
> questions:
> 1- Should the predicted values be linear or exponential?
> 2- Is the predict.arima function appropriate to do this?
> Thanks in advance. 
> 
> 
> Felipe D. Carrillo  
> Supervisory Fishery Biologist  
> Department of the Interior  
> US Fish & Wildlife Service  
> California, USA
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



More information about the R-help mailing list