extrapolate in R for a time-series data -
I have time-series data for the past 20 years. Variables are measured every year so I have 20 values. Close is a tab-delimited file in which the first column is represented and the second column is the value. This is what it likes: I want to extrapolate the value of the second column for the coming years. The rate at which rate is decreasing in the second column is also going down, so I think we can not use linear regression. I want to know which year will the second column reach the value of zero. I have never used R, it would be great if you could also help me with code that will be used to read data from a tab-delimited file. Thanks The following is a sketch that can help you get started . In this case our model says that the line If it does not make any sense then you want to choose a different model. Whatever model you choose, graph the data with the result so that you can see how well you are doing. / P>
## Get Data & lt; - read.table (text = "1991 438 1992 408 1993 381 1994 361 1995 338 1996 315 1997 28 9 1998 261 1999 22 9 2000 206 2001 190 2002 173 2003 151 2004 141 2005 126 2006 108 2007 99 2008 93 2009 85 2010 77 2011 71 2012 67 ", col.names = c (" year "," value ")) library (ggplot2) ## Developed a model TMP $ pred1 and lt; - GG Plot (TMP, AES (X = year, Y = value)) + GOM_LINE () + - Predictive (LM (value ~ shift (year, 2), data = TMP) ## View data; Geom_point () + geom_hline (Aes (yintercept = 0)) Print (P1) ## Model P1 + geom_line (AES (y = pred1), color = "red") ## Model pred and lt; - Check extrapolation based on data .frame Year = 1990: 2050) pred $ value & lt; - prediction (LM (value = shift (year, 2), data = tmp), new data = pred) p1 + geom_line (color = "red", data = pred) / Code>
Comments
Post a Comment