# Teaching statistics with R

I started writing these notes in March 2009. I have further updates in this blog post, together with some discussion on software tools.

## March 2009

In March 2009 I started explaining my position on using R (and R commander) for teaching purposes. Forestry deals with variability and variability is the province of statistics. The use of statistics permeates forestry: we use sampling for inventory purposes, we use all sort of complex linear and non-linear regression models to predict growth, linear mixed models are the bread and butter of the analysis of experiments, etc.

I think it is fair to expect foresters to be at least acquainted with basic statistical tools, and we have two courses covering ANOVA and regression. In addition, we are supposed to introduce/reinforce statistical concepts in several other courses. So far so good, until we reach the issue of software.

During the first year of study, it is common to use MS Excel. I am not a big fan of Excel, but I can tolerate its use: people do not require much training to (ab)use it and it has a role to introduce students to some of the ’serious/useful’ functions of a computer; that is, beyond gaming. However, one can hit Excel limits fairly quickly which–together with the lack of audit trail for the analyses and the need to repeat all the pointing and clicking every time we need an analysis–makes looking for more robust tools very important.

Until the end of 2009 SAS (mostly BASE and STAT, with some sprinkles of GRAPH) was our robust tool. SAS was introduced in second year during the ANOVA and regression courses. SAS is a fine product, however:

- We spent a very long time explaining how to write simple SAS scripts. Students forgot the syntax very quickly.
- SAS’s graphical capabilities are fairly ordinary and not at all conducive to exploratory data analysis.
- SAS is extremely expensive, and it is dubious that we could afford to add the point and click module.
- SAS tends to define the subject; I mean, it adopts new techniques very slowly, so there is the tendency to do only what SAS can do. This is unimportant for undergrads, but it is relevant for postgrads.
- Users tend to store data in SAS’s own format, which introduces another source of lock-in.

In my research work I use mostly ASReml (for specialized
genetic analyses) and R (for general work), although I
have moved towards using `asreml-R`

(an R library that interfaces ASReml) to
have a consistent work environment. For teaching I used SAS to be consistent
with second year material.

Considering the previously mentioned barriers for students I started playing with R-commander, a cross-platform GUI for R created by John Fox (the writer of some very nice statistics books, by the way). As I see it:

- Its use in command mode is
*not more difficult*(but not simpler either) than SAS. I think that SAS is more consistent and they have worked hard at keeping a very similar structure between`PROC`

s. - We can get R-commander to start working right away with simple® methods, while maintaining the possibility of moving to more complex methods later by typing commands or programming.
- It is free, so our students can load it into their laptops and keep on using it when they are gone. This is particularly true with international students: many of them will never see SAS again in their home countries.
- It allows an easy path to data exploration (pre-requisite for building decent models) and high quality graphs.
- R is open source and easily extensible.

I think that R will be an excellent fit for teaching; nevertheless, there would be a few drawbacks, mostly when dealing with postgrads:

- There are restrictions to the size of datasets (they have to fit in
memory), although there are ways to deal with some of the restrictions. On the
other hand, I have hit the limits of
`PROC GLM`

and`PROC MIXED`

before and that is where ASReml shines. - Some people have an investment in SAS and may not like the idea of using a different software.

We will see how it goes because–as someone put it many years ago–there is always resistance to change:

It must be remembered that there is nothing more difficult to plan, more doubtful of success, nor more dangerous to manage, than the creation of a new system. For the initiator has the enmity of all who would profit by the preservation of the old institutions and merely lukewarm defenders in those who would gain by the new ones.—Niccolò Machiavelli, The Prince, Chapter 6.

## August 2009

In March 2009 I posted an explanation of the issues behind getting R accepted in our School for teaching statistics.

At School level, I needed to spend substantial time compiling information to prove that R could satisfy my colleagues’ statistical needs. Good selling points were lme4, lattice/ggplot2 and pointing my most statistically inclined colleagues to CRAN. Another important issue was the ability to have a GUI (Rcmdr) that could be adapted to our specific needs. We will develop an extra menu item to fit non-linear models for growth models used in forestry. Our School has now adopted R as the default software for teaching any statistical content during the four years of the curriculum.

At the university level, my questions to the department of Mathematics and Statistics sparkled a lot of internal discussion, which resulted in R being adopted as the standard software for some of the second year courses (it was already the standard for most courses in 3rd and 4th year). The decision was not unanimous, particularly because for statisticians knowing SAS is one of those ‘must be in the CV’ skills, but they went for change. The second year courses are offered across colleges, which makes the change very far reaching. These changes will also imply that in the near future many computers in the university will come with R pre-installed.

## April 2010

R and R-commander are installed in our computer labs and we have started using them in our Research Methods course. It is still too early to see what will be the effect of R versus SAS, but we expect to see an increase on the application of statistics within our curriculum.

One thing that I did not properly considered before are the annoying side-effects of the university’s computer policies. Students are not allowed to install software in the university computers and R packages fall within that category. We can either stay with the defaults + R commander (our current position) or introduce an additional complication for students, pushing them to define their own library location. I’d rather teach ggplot2 than lattice, but ggplot2 is an extra installation. Choices, choices…

## March 2011

Comments after teaching a regression modeling course using R-commander:

- Some students really appreciate the possibility of using R-commander as their ‘total analysis system’. Most students that have never used a command line environment prefer it.
- Students that have some experience with command-line work do not like much R-commander; even finding it confusing. Some of them could not see the point of using an underpowered environment.
- Data transformation facilities in R-commander are somewhat limited to the simplest cases.
- The OS X version of R-commander (under X Windows) is butt ugly.

In general, R would benefit of having a first-class Excel import system that worked across platforms. Yes, I know that some people say that researchers should not use Excel; however, there is a distinction between normative and positive approaches to research. People do use Excel and insisting that they should not is not helpful.