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

From: Andrew Robinson <A.Robinson_at_ms.unimelb.edu.au>
Date: Sat, 03 May 2008 07:01:49 +1000

On Sat, May 03, 2008 at 06:43:22AM +1000, Andrew Robinson wrote:
> 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 ...

Or (possibly better) make time a factor.  

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 = factor(rep(c(1,2), 1600)),
	subject=rep(1:1600, each=2))

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


Andrew  

> 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/

-- 
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/

______________________________________________
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.
Received on Fri 02 May 2008 - 21:41:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 02 May 2008 - 22:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive