[R] Fitting polynomial (power greater than 2)
538280 at gmail.com
538280 at gmail.com
Thu Feb 9 23:11:31 CET 2012
This looks like homework, which is generally discouraged here. You
should at the least admit that it is homework and tell what resources
your teacher has OK'd you to use.
Since you did show what you have done so far and are not just asking
for a handout, here is a hint:
?poly
On Tue, Feb 7, 2012 at 9:34 PM, dkendall44 <dkendall44 at gmail.com> wrote:
> Hey all, first time poster here. I'm new to R and working on my first real
> programming and forecasting asignment. I'm using unemployment data from
> 1948-2012. I successfully completed part a and the linear fit for part b,
> but i am really struggling fitting a polynomial with a power greater than 2
> to my forecast. I'll upload my R code at the bottom. Any help is very much
> appreciated! Thank You!
>
> (a) Produce a time-series plot of your data.
> (b) Fit linear, polynomial (use a power greater than 2), and R’s best fit
> models to your series.
>
> rm(list=ls(all=TRUE))
> z=read.table("longtermunempdata.txt")
> names(z)= c("Unemployment")
> attach(z)
> TIME=seq(1,769,by=1)
>
> Unemployment_ts<-ts(Unemployment,start=1948,freq=12)
> #quartz()
> #plot(stl(Unemployment_ts,s.window="periodic"))
>
> #1A
> quartz()
> plot(TIME, Unemployment, xlab="Year", ylab="Long Term
> Unemployment",type='l')
>
> #1B Linear
> quartz()
> plot(TIME,Unemployment,type="l", xlab="Year",ylab="Long Term Unemployment")
> modelu=lm(Unemployment~TIME)
> summary(modelu)
> abline(modelu,col="red3")
>
> modelu=lm(Unemployment~TIME)
> #1B Linear vs TS
> quartz()
> par(mfrow=c(2,1))
> plot(TIME, Unemployment, xlab="Year", ylab="Long Term
> Unemployment",type='l')
> abline(modelu,col="red3",lwd=2)
> plot(TIME,modelu$res,xlab="Year",ylab="Long Term Unemployment",type='l')
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Fitting-polynomial-power-greater-than-2-tp4368026p4368026.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com
More information about the R-help
mailing list