[R-sig-ME] Fwd: Error using nlme; Malformed factors

Thierry Onkelinx thierry.onkelinx at inbo.be
Thu Dec 22 10:39:45 CET 2016


Dear Yoke Yong,

You need to transform Time from a factor to an integer.

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-12-22 2:09 GMT+01:00 Wong Yoke Yong <yokeyong.wong op gmail.com>:

> Hi all,
>
> Please refer to the attached message.
>
>
> Regards,
> Yoke Yong
>
> ---------- Forwarded message ----------
> From: Wong Yoke Yong <yokeyong.wong op gmail.com>
> Date: Wed, Dec 21, 2016 at 10:24 AM
> Subject: Error using nlme; Malformed factors
> To: r-help op r-project.org
>
>
> HI all,
>
> I am using the nlme package to learn multilevel models, and following
> examples from the textbook "Discovering Statistics Using R" when it
> happened.
>
> [Mixed Models Code][1]
>
> The data set is Honeymoon Period.dat, also downloadable under their
> companion website.
>
> [Data Set - Multilevel Models][2]
>
>     require(nlme)
>     require(reshape2)
>     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",
> "Life_Satisfaction")
>
>
>     #print(restructuredData)
>     #restructuredData.sorted<-restructuredData[order(Person),]
>
>     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 =
> list(opt="optim"))
>     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!
>
>   [1]: https://studysites.uk.sagepub.com/dsur/study/DSUR%20R%
> 20Script%20Files/Chapter%2019%20DSUR%20Mixed%20Models.R
>   [2]: https://studysites.uk.sagepub.com/dsur/study/articles.htm
>
>
> Regards,
> Yoke Yong
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models op r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list