# Example R code for STAT 520 HW 2 #1 library(astsa);data(cmort) temp = tempr-mean(tempr) # center temperature temp2 = temp^2 trend = time(cmort) # time fit = lm(cmort~ trend + temp + temp2 + part, na.action=NULL) summary(fit) # regression results AIC(fit) # AIC BIC(fit) # BIC card.mort = ts.intersect(cmort, temp, temp2, trend, part, partL4=lag(part,-4)) summary(fit1 <- lm(cmort~ temp+ temp2+ trend+ part+ partL4,data=card.mort,na.action=NULL)) AIC(fit1) BIC(fit1) #3 library(TSA); data(prescrip) #(b) har.=harmonic(prescrip,m=1) model.har.pre=lm(prescrip~har.+time(prescrip)) #(g) lin.trend=lm(prescrip~time(prescrip)) month.=season(prescrip) model2=lm(resid(lin.trend)~month.-1) # -1 removes the intercept term summary(model2) AIC(model.har.pre) BIC(model.har.pre) AIC(model2) BIC(model2)