Dear R-help list, I have grouped data, looking like this: cases <- c(23,12,56,81) total <- c(123,234,248,390) x1 <- c(0,0,1,1) x2 <- c(0,1,0,1) Data <- as.data.frame(cbind(cases,total,x1,x2)) Data I would like to run a logistic regression with group weights on these, where cases and (total-cases) are equal to the group weights (w). My final data would look like: w <- c(100,23,222,12,192,56,309,81) y <- c(0,1,0,1,0,1,0,1) x1 <- c(0,0,0,0,1,1,1,1) x2 <- c(0,0,1,1,0,0,1,1) Data.long <- as.data.frame(cbind(w,y,x1,x2)) Data.long Any suggestions? All the best, Oystein Myrland [[alternative HTML version deleted]]
one approach is: Data.long <- with(Data, data.frame( w = c(rbind(total - cases, cases)), y = rep(0:1, nrow(Data)), x1 = rep(x1, each = 2), x2 = rep(x2, each = 2) )) I hope it helps. Best, Dimitris Myrland ?ystein wrote:> Dear R-help list, > > > > I have grouped data, looking like this: > > > > cases <- c(23,12,56,81) > > total <- c(123,234,248,390) > > x1 <- c(0,0,1,1) > > x2 <- c(0,1,0,1) > > > > Data <- as.data.frame(cbind(cases,total,x1,x2)) > > Data > > > > I would like to run a logistic regression with group weights on these, > where cases and (total-cases) are equal to the group weights (w). > > > > My final data would look like: > > > > w <- c(100,23,222,12,192,56,309,81) > > y <- c(0,1,0,1,0,1,0,1) > > x1 <- c(0,0,0,0,1,1,1,1) > > x2 <- c(0,0,1,1,0,0,1,1) > > > > Data.long <- as.data.frame(cbind(w,y,x1,x2)) > > Data.long > > > > Any suggestions? > > > > All the best, > > Oystein Myrland > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
Whoops, forgot to cc. the list... -pd Myrland ?ystein wrote:> Dear R-help list, > > > > I have grouped data, looking like this: > > > > cases <- c(23,12,56,81) > > total <- c(123,234,248,390) > > x1 <- c(0,0,1,1) > > x2 <- c(0,1,0,1) > > > > Data <- as.data.frame(cbind(cases,total,x1,x2)) > > Data > > > > I would like to run a logistic regression with group weights on these, > where cases and (total-cases) are equal to the group weights (w). > > > > My final data would look like: > > > > w <- c(100,23,222,12,192,56,309,81) > > y <- c(0,1,0,1,0,1,0,1) > > x1 <- c(0,0,0,0,1,1,1,1) > > x2 <- c(0,0,1,1,0,0,1,1) > > > > Data.long <- as.data.frame(cbind(w,y,x1,x2)) > > Data.long > > > > Any suggestions?Er, why? summary(glm(cbind(cases,total-cases)~x1+x2, data=Data, family=binomial)) summary(glm(cases/total~x1+x2,weights=total,data=Data, family=binomial)) seems to work just fine, with same results as summary(glm(y~x1+x2,weights=w, data=Data.long, family=binomial)) (BTW, beware the residual deviance in the Data,long analysis. The saturated model is not what you might think.) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907