[R] predicting values into the future
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Sun Apr 5 09:09:42 CEST 2009
Here is a bit of an exploration of your data but first a couple of notes.
* the information about Excel is probably a bit superfluous here. Some of us have no idea about Excel, and rather hope it can stay that way.
* 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/
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Felipe Carrillo
Sent: Sunday, 5 April 2009 4:13 PM
To: r-help at stat.math.ethz.ch
Subject: [R] predicting values into the future
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