Multilevel modeling in R on a Mac

Peter Goff wrote:

I’m using your text, Data Analysis Using Regression & Multilevel/Hierarchical Models as the basis for an independent study class this fall. I am fairly adapt with Stata, however I have no expertise in R (changing this condition is a goal of the independent study!).

I’m working to get up and running with the examples from the book, but I’m running into several problems, all apparently stemming from my having a Mac as opposed to a PC. Specifically I cannot load the “arm” library because I cannot install the lme4 library as lme4 is not available for Macs.

Yu-Sung replied:

Here are steps for you to install lme4:

1. update your x11 code for Mac system (so that you have gcc and g77 complier)

2. download source code for lme4 from the CRAN.

3. install lme4 from the source you just downloaded.

I am not a Mac user. I am adapting steps from installing lme4 in a linux OS. But we have colleagues here following the same instructions and make lme4 working on their machine.

8 thoughts on “Multilevel modeling in R on a Mac

  1. I was able to install lme4 on my Mac by issuing the following command in R:

    install.package("lme4")

    This installed a pre-compiled package, so having the Xcode utilities may not be required. (Though if you don't have a compiler on your computer, is it really a computer?)

  2. I'm guessing the "x11 code for Mac system" is a telephone version of "Xcode", Apple's IDE and compilation tool set.

    Tips on compiling R code on OSX: http://r.research.att.com/tools/

    Steps 2 can be skipped too. I installed lme4 with the Package Installer feature in the Mac GUI for R. Just choose "CRAN (sources)" as the repo and click to install lme4. It will download, compile and install in one go.

  3. You can just use the GUI commands. From the "packages and data" menu, choose "package installer". From the "CRAN binaries" list, find lme4 and click the "install selected button". Then go to "package manager" ("packages and data" menu again) and select it so it is loaded.

  4. i'm using this textbook for my data analysis class this fall (with some of the same "force myself to learn more R motives") and I'm sure somebody will use a MAC. This is extremely useful against that contingency.

    Thanks!

  5. The binary build apparently failed because of included tests. While a slight inconvenience, you can combine steps 2&3 with <pre>install.packages("lme4",type="source")</pre> in R, provided that you have a build environment (step 1). Xcode for mac is free but you do have to register.

  6. I use Macs. I'm on Snow Leopard, ymmv.

    @Turadg:
    x11 is a unix based windowing system, it's not directly related to Xcode (apart from the fact that installing Xcode on your Mac also installs).

    And with regard to Yu-Sung's comment "update your x11 code for Mac system", I believe what he means to say is to make sure you have the Developers Tools installed on your Mac. Your OS X install DVD contains on it a directory, 'Optional Installs', which contains 'Xcode.mpkg'. Install that, use all the defaults, that will install gcc and all the other compilers you need. Either that or their making an oblique reference to the XQuartz program (http://xquartz.macosforge.org/trac/wiki).

    @Charlie and @David:
    I just checked my R (2.11.1), and install.packages('lme4') doesn't work for me, so I think the suggestion to download source from CRAN is a good one for some folks.

  7. I think lme4 has problems with R 2.11 on Macs. You cannot just install lme4 as usual using install.packages('lme4'). I recall trying to find a solution but all the ones mentioned in some forum didn't work for me so I just reinstalled R 2.10 and everything worked perfectly!

  8. I was able to get lme4 up and running after jumping through a few hoops, although downloading from source didn't work for me. This suggestion comes from Mark Grant and this may be a solution for other folks in the same situation:

    install.packages("lme4",,"http://r.research.att.com/&quot;,type='mac.binary.untested')

Comments are closed.