[R] Fitting polynomial (power greater than 2)

dkendall44 dkendall44 at gmail.com
Wed Feb 8 05:34:19 CET 2012


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.



More information about the R-help mailing list