library(stargazer) sample1<-("http://kanggc.iptime.org/book/data/korea(77-93)-1.txt") sample1_dat<-read.delim(sample1,header=T) gnp<-ts(sample1_dat$gnp, start=c(1977,1), frequency=4) def<-ts(sample1_dat$def, start=c(1977,1), frequency=4) m2<-ts(sample1_dat$m2, start=c(1977,1), frequency=4) ols.res<-lm(m2~gnp+def) summary(ols.res) res<-resid(ols.res) res.t<-ts(res) plot(sample1_dat$gnp, res.t^2,main="Squares of Residual plotting") plot(sample1_dat$def, res.t^2,main="Squares of Residual plotting") #LM test n<-length(res) res.t.sq<-res.t^2 gnp.sq<-gnp^2 def.sq<-def^2 (res.aux<-lm(res.t.sq~gnp+def+gnp.sq+def.sq+gnp*def)) lm<-n*summary(res.aux)$r.squared lm (pchisq(lm, df=5, lower.tail=F)) library(tigerstats) pchisqGC(19.65366, df=5, region="above", graph=T)