6.4 Diagnostic checking in RStudio
Diagnostic checking in R Studio requires installation of additional packages Using sample data from a text file “eu_countries.txt” estimate multivariate model by OLS method
Perform diagnostic checking of the model (\(\alpha=0.05\)). Compute \(White's\) robust standard errors. Also, apply WLS method (take inverse values of \(population_i\) as weights \(w_{ii}\)). Summarize all results together in a single table using stargazer()
command. Add three rows to a given table considering degrees of freedom \(df\), \(R-squared\) and \(F-statistic\).
=read.table(file="http://www.efzg.hr/
mydatauserdocsimages/sta/jarneric/eu_countries.txt",header=TRUE)
## OLS estimation of multivariate model
=lm(gdp~population+unemployment,mydata)
model## Coefficients with significance testing
install.packages("lmtest")
library(lmtest)
coeftest(model)
Continued …
## Variance inflation factors
install.packages("car")
library(car)
vif(model)
## BP test using studentized residuals
bptest(model)
## BP test using ordinary residuals
bptest(model,studentize=FALSE)
## BP test using squared regressors and interaction terms
bptest(model,~population+unemployment+I(population^2)+
I(unemployment^2)+population:unemployment,
studentize=FALSE,mydata)
## First order autocorrelation coefficient of residuals
cor(resid(model)[-1],resid(model)[-18])
Continued …
## One-sided DW test
dwtest(model)
## Two-sided DW test
dwtest(model,alternative="two.sided")
## First order BG test
bgtest(model)
## Second order BG test
bgtest(model,order=2)
## Normality test of residuals
install.packages("tseries")
library(tseries)
jarque.bera.test(resid(model))
## Matrix "Gamma-hat" and ordinary standard errors
vcov(model)
sqrt(diag(vcov(model)))
Continued …
## Matrix "Gamma-tilde" and robust standard errors
hccm(model,type="hc0")
sqrt(diag(hccm(model,type="hc0")))
## Significance testing using robust standard errors
coeftest(model,vcov=hccm(model,type="hc0"))
## WLS estimation method
=lm(gdp~population+unemployment,weights=1/population,
modelw mydata)