How to Use R and Its Packages
About R Free software For statistical computing and graphics R homepage: We use R for windows – Current version: R for windows
First Things to Know R regards things as objects – Datasets and the results of a regression are objects All commands are functions Text command and case sensitivity Interactive mode and batch mode
Reading Data mydata=read.table(“filename.txt”, header=T) – Text file with a header above each column mydata=read.csv(“filename.txt”, header=T) – Excel csv file with a header above each column attach(mydata)
Packages We Need AER quantreg plm rqpd
Installation install.packages("fBasics",repo=" Or from the menu bar
Installation of rqpd First, install “quantreg”, “Formula” and “SparseM” install.packages(“rqpd",repos="
Descriptive Statistics Package: fBasics Function: basicStats(mydata)
Linear Model: OLS Output=lm(y~x1+x2+x3) summary(Output)
Testing a Linear Hypothesis Package: car (in AER) H0:Rβ=r Function: linearHypothesis(Output, hypothesis.matrix= R, rhs=r) Example: H0: β1=0 and β2=0 – R=rbind(c(0,1,0,0),c(0,0,1,0)) – r=c(0,0)
Testing a Restricted Model Function: anova(output of restricted, output of unrestricted)
Testing under Heteroskedasicity
Robust Standard Errors and Tests Packages: sandwich, lmtest (both in AER) Functions: – coeftest(output, vcov=vcovHC) – waldtest(outputr, outputur, vcov=vcovHC(outputur))