Archive for the 'R' Category

Quantile regression in R

Roger Koenker, a quantile regression crusader, has an R package that implements the procedure. It is called quantreg, and it is documented here. This package has apparently been around for quite some time, but I was only recently turned on to quantile regression, so it was under my radar.

Rattle: an R GUI

Rattle is a graphical interface to R. It supports basic data management tasks, as well as a number of different modeling functions. I haven’t had a chance to test it out yet since I don’t have my R installation  completely up to date, but it looks promising. For all of R’s strengths, one weakness is [...]

The plm package for R lets you run a number of common panel data models, including

The fixed effects (or within) estimator
The random effects GLS estimator

It also allows for general GLS estimation, as well as GMM estimation, and includes a feature for heteroscedasticity consistent covariance estimation.
It’s very easy to use, it simply requires that you [...]

Quick-R: a great R tutorial site

Quick-R, by Robert Kabacoff, is a wonderful R introduction site. It covers data management, basic and advanced statistics, and graphing in R, and it is aimed at an audience that has previous experience using other packages (such as SAS or Stata) that work differently than R.

I recently lost my documentation folder (oops), so I had to go online and retrieve the documentation files and tutorials that I find indispensible for working. I decided I’d save myself and everyone else the trouble by posting the list here. All of the files are available in PDF format.

All R manuals
Scilab documentation. Currently the [...]

Smultron is an open-source text-editor for OS X. It’s a very lean editor, but it’s fast and it was written in Cocoa. Out of the box it has syntax highlighting for Stata and LaTeX, but not R. Basic instructions for adding a rudimentary R syntax coloring file are available here. However, I have adapted the [...]

The situation: you have two datasets with a common variable, and you want to incorporate both into one large dataset containing all of the variables. This is called merging data, and it’s easy to do in any standard statistical package. In these examples, I assume that there is only one variable between any datasets to [...]

Via this page, I just learned that there is a TextWrangler Language Module for R. The file itself is available here.
To install, copy the .plist file to the following directory
Username/Library/Application Support/TextWrangler/Language Modules
I also recommend going into TextWrangler’s preferences and changing the color for comments. The default is a gray color that doesn’t provide a lot [...]

Basic factor analysis in R

The call to perform factor analysis on a set of variables in R is:
fact1<- factanal(x,factors,scores=c(“regression”),rotation=”varimax”)
where “x” is a dataframe containing the appropriate variables, and “factors” is the number of factors to be extracted.
socres=”…” and rotation=”…” are optional, and varimax is the default rotation.
The factanal function doesn’t seem to handle missing observations well, so it’s easier [...]

Getting tables from R output

Turning plain-text output into well-formatted tables can be a repetitive task, especially when many tests or models are being incorporated into a paper.
For R users, there are several methods that can make this task easier (though not much less repetitive), regardless of what typesetting system you use.
LaTeX tables
The xtable package produces LaTeX-formatted tables. Using xtable, [...]

Loops in R

Loops in R are similar to arrays in SAS — they allow you to work with multiple variables at the same time (among other things). For example, you can use a list to recode several variables in one step. For example,
yesnovars<-data.frame(x1,x2,x3)
for(i in 1:length(yesnovars)) {
yesnovars[[i]]=recode(yesnovars[[i]],”c(‘Y’)=1;c(‘N’)=0″)
}
would
1) Make a dataframe called “yesnovars” containing the three variables x1, [...]

Testing and correcting for heteroscedasticity is probably more convenient in R that it is in SPSS or SAS, probably because those packages weren't designed especially for econometric analysis, and R users have the CAR package at their disposal.
Testing
The easiest way to test for heteroscedasticity is to use the non-constant variance test function that is included [...]

SubEthaEdit and R

SubEthaEdit is a “powerful and lean” text editor for Mac OS X — enough features to be suitable for programming and coding tasks, but not so many features that it becomes complicated. SubEthaEdit is also known for its collaboration features.
One nice feature of the editor is that an R/S-Plus Editing Mode is available, which includes [...]

R Commander

About R Commander
R Commander is a graphical user interface for R. The interface includes functions for

importing and managing data
conducting simple statistical tests
linear and logisitic models and diagnostics
graphs
probability distributions

as well as other functions.

R Commander on OS X under X11
Availability
R Commander works automatically with Windows and some Linux distributions.
R Commander works on Mac OS X, with two [...]

R packages

R packages are add-ons that increase the range of utility, analytical and other functions that R can handle.
Installation and use
The easiest way to install packages is to use the command
install.packages(“PackageName”)
This presupposes that you are connected to the internet, and requires that you select a CRAN mirror. It is also possible to download packages to your [...]

The SendToR for TextWrangler AppleScript simply sends R routines to R from within TextWrangler. Aspects of the R program such as setting the working directory or creating a sink file are left to the user. If you want a Stata-style log, I suggest using the command:
sink(“filename.txt”,split=TRUE)
which will save the output to filename.txt but also display [...]

“Batch” R

One nice feature of SAS is the ability to run programs in batch mode (without launching the SAS System). R has this facility to an extent via the source() command, but still requires that the application be running.
I have written a Batch R AppleScript that allows you to run an R routine without having to [...]

Getting started with R

There are many how-to’s and books on using R, but most are aimed at experienced users who have already familiarized themselves with the basics of R. Getting started can be difficult for those with little experience using statistical software, those used to graphical software, or for those who simply don’t have access to the correct [...]

Running R routines

The default mode of interaction with R is the console’s command line. This can be a convenient way of using R — it’s interactive, so you can make real time changes to your data and models. However, there are times when it might be more convenient to write a routine beforehand, run it in R, [...]

An R quick reference

I have put together a quick reference (PDF) of common R commands for data management and basic statistical tests.

About R

R is an open-source statistics package. It is highly extensible — the core package comes with many statistical routines, R’s functionality can easily be extended by installing optional packages, and the R language can be used to write new packages. From the R Project website:
R is a language and environment for statistical computing and graphics. [...]




  • Quick navigation

  • Categories