[R] GLMM and data manipulation (2nd try)

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Fri May 2 22:43:22 CEST 2008


On Fri, May 02, 2008 at 03:06:31PM -0500, Giovanni Petris wrote:
> 
> Hello,
> 
> I posted a question yesterday but I got no replies, so I'll try to
> reformulate it in a more concise way. 
> 
> I have the following data, summarizing approval ratings on two
> different surveys for a random sample of 1600 individuals:
> 
> > ## Example: Ratings of prime minister (Agresti, Table 12.1, p.494)
> > rating <- matrix(c(794, 86, 150, 570), 2, 2)
> > dimnames(rating) <- list(First = c("approve", "disapprove"),
> +                          Second = c("approve", "disapprove"))
> > rating
>             Second
> First        approve disapprove
>   approve        794        150
>   disapprove      86        570
> 
> I would like to fit a logit model with approve/disapprove as response,
> survey (first/second) as a fixed effect, and subject as a random
> effect. 
> 
> 1) Is it possible to fit such a model directly using "lmer"?
> 
> or 
> 
> 2) Should I unroll the table above into a dataframe containing also
>    fictitious subject id's? If this is the case, what is a clean way
>    of doing it? 


Unroll it. 

Asking for a "clean" way to do something is a disincentive because it
implies that you know how to do it but not cleanly.  In the future I
would suggest that you do one of two things

a) post your on dirty version and ask for a cleaner one, or

b) just ask for something that works.
 
Something like ...

ratings <- 
	data.frame(
	response = c(
		 rep(c(1,1), 794), 
		 rep(c(1,0), 150),
		 rep(c(0,1),  86),
		 rep(c(0,0), 570)),
	time = rep(c(1,2), 1600),
	subject=rep(1:1600, each=2))

test.lmer <- lmer(response ~ time + (1|subject), data=ratings,
     	     family=binomial)

but I don't know if you think that's clean or not.

Andrew
 
> Thank you in advance,
> Giovanni Petris
> 
> -- 
> 
> Giovanni Petris  <GPetris at uark.edu>
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-6410
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/



More information about the R-help mailing list