130 likes | 287 Views
How to Use R and Its Packages. About R. Free software For statistical computing and graphics R homepage: www.r-project.org We use R 2.15.3 for windows Current version: R 3.0.1 for windows. First Things to Know. R regards things as objects
E N D
About R • Free software • For statistical computing and graphics • R homepage: www.r-project.org • We use R 2.15.3 for windows • Current version: R 3.0.1 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="http://cran.cs.pu.edu.tw",dep=T) • Or from the menu bar
Installation of rqpd • First, install “quantreg”, “Formula” and “SparseM” • install.packages(“rqpd",repos="http://R-forge.R-project.org”)
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)
Robust Standard Errors and Tests • Packages: sandwich, lmtest (both in AER) • Functions: • coeftest(output, vcov=vcovHC) • waldtest(outputr, outputur, vcov=vcovHC(outputur))