R on linux: factorial repeated-measures design as a GLM causing problems

Home Forums Methodspace discussion R on linux: factorial repeated-measures design as a GLM causing problems

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1233

    R on linux: factorial repeated-measures design as a GLM causing problems

    I was working throught an example in Andy Fields book Discovering statistics using R that was quite similar to the analysis I have to carry out on my dataset. Unfortunately I kept on getting an error message when I ran the example code on the example data.

    I subsequently updated to the newest version of R and reinstalled the required packages, but got the same error. I then saved the code and ran it on someones Windows 8 machine and the code worked just fine.

    As far as I can tell the issue has to do with difference between R in Linux vs R in Windows.

    Below is the code required to generate the error when running in R (3.0.2) on a linux machine (Linux Mint 14, 64-bit):

    #Install required packages

    install.packages(“nlme”)

    library(nlme)

    #Enter data by hand

    participant<-gl(20, 9, labels = c(“P01”, “P02”, “P03”, “P04”, “P05”, “P06”, “P07”, “P08”, “P09”, “P10”, “P11”, “P12”, “P13”, “P14”, “P15”, “P16”, “P17”, “P18”, “P19”, “P20” ))

    drink<-gl(3, 3, 180, labels = c(“Beer”, “Wine”, “Water”))

    imagery<-gl(3, 1, 180, labels = c(“Positive”, “Negative”, “Neutral”))

    groups<-gl(9, 1, 180, labels = c(“beerpos”, “beerneg”, “beerneut”, “winepos”, “wineneg”, “wineneut”, “waterpos”, “waterneg”, “waterneut”))

    attitude<-c(1, 6, 5, 38, -5, 4, 10, -14, -2, 26, 27, 27, 23, -15, 14, 21, -6, 0, 1, -19, -10, 28, -13, 13, 33, -2, 9, 7, -18, 6, 26, -16, 19, 23, -17, 5, 22, -8, 4, 34, -23, 14, 21, -19, 0, 30, -6, 3, 32, -22, 21, 17, -11, 4, 40, -6, 0, 24, -9, 19, 15, -10, 2, 15, -9, 4, 29, -18, 7, 13, -17, 8, 20, -17, 9, 30, -17, 12, 16, -4, 10, 9, -12, -5, 24, -15, 18, 17, -4, 8, 14, -11, 7, 34, -14, 20, 19, -1, 12, 43, 30, 8, 20, -12, 4, 9, -10, -13, 15, -6, 13, 23, -15, 15, 29, -1, 10, 15, 15, 12, 20, -15, 6, 6, -16, 1, 40, 30, 19, 28, -4, 0, 20, -10, 2, 8, 12, 8, 11, -2, 6, 27, 5, -5, 17, 17, 15, 17, -6, 6, 9, -6, -13, 30, 21, 21, 15, -2, 16, 19, -20, 3, 34, 23, 28, 27, -7, 7, 12, -12, 2, 34, 20, 26, 24, -10, 12, 12, -9, 4)

    longAttitude<-data.frame(participant, drink, imagery, groups, attitude)

    #Setting contrasts

    AlcoholvsWater<-c(1, 1, -2)

    BeervsWine<-c(-1, 1, 0)

    NegativevsOther<-c(1, -2, 1)

    PositivevsNeutral<-c(-1, 0, 1)

    contrasts(longAttitude$drink)<-cbind(AlcoholvsWater, BeervsWine)

    contrasts(longAttitude$imagery)<-cbind(NegativevsOther, PositivevsNeutral)

    #Running the factorial repeated-measures design as a GLM

    baseline<-lme(attitude ~ 1, random = ~1|participant/drink/imagery, data = longAttitude, method = “ML”)

    drinkModel<-update(baseline, .~. + drink)

    imageryModel<-update(drinkModel, .~. + imagery)

    attitudeModel<-update(imageryModel, .~. + drink:imagery)

    anova(baseline, drinkModel, imageryModel, attitudeModel)

    Error Message

    I get as far as running the first part of the model (i.e., baseline<-lme…). However, when I go on the add the next factor (i.e., + drink), I get the following error:

    Error in solve.default(-val) : Lapack routine dgesv: system is exactly singular: U[2,2] = 0

    I looked up this error code and found out that: The error message is telling you that your matrix is singular and cannot be inverted.

    The funny thing is that running the same code on the same version of R on a Windows machines runs the code just fine.

    Any help on this issue would be appreciated.

    Cheers,

    Marty

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.