[R] Error using nlme; Malformed factors

Wong Yoke Yong yokeyong.wong at gmail.com
Wed Dec 21 03:24:10 CET 2016

HI all,

I am using the nlme package to learn multilevel models, and following
examples from the textbook "Discovering Statistics Using R" when it

[Mixed Models Code][1]

The data set is Honeymoon Period.dat, also downloadable under their
companion website.

[Data Set - Multilevel Models][2]

    satisfactionData = read.delim("Honeymoon Period.dat",  header = TRUE)

    restructuredData<-melt(satisfactionData, id = c("Person", "Gender"),
measured = c("Satisfaction_Base", "Satisfaction_6_Months",
"Satisfaction_12_Months", "Satisfaction_18_Months"))
    names(restructuredData)<-c("Person", "Gender", "Time",


    intercept <-gls(Life_Satisfaction~1, data = restructuredData, method =
"ML", na.action = na.exclude)
    randomIntercept <-lme(Life_Satisfaction ~1, data = restructuredData,
random = ~1|Person, method = "ML",  na.action = na.exclude, control =
    anova(intercept, randomIntercept)

    timeRI<-update(randomIntercept, .~. + Time)
    timeRS<-update(timeRI, random = ~Time|Person)
    ARModel<-update(timeRS, correlation = corAR1(0, form = ~Time|Person))

The error occured at this moment, when I am trying to update "timeRS"
model. The error is as follows:

    Error in as.character.factor(X[[i]], ...) : malformed factor

Help would be appreciated. Thanks!

  [2]: https://studysites.uk.sagepub.com/dsur/study/articles.htm

Yoke Yong

	[[alternative HTML version deleted]]

More information about the R-help mailing list