Hi: Here's a simple example of its use using the data from Montgomery, Myers and Vining (2002), problem 4.7:
ex4.7 <- structure(list(pressure = c(2500L, 2700L, 2900L, 3100L, 3300L, 3500L, 3700L, 3900L, 4100L, 4300L), nfast = c(50L, 70L, 100L, 60L, 40L, 85L, 90L, 50L, 80L, 65L), nfailures = c(10L, 17L, 30L, 21L, 18L, 43L, 54L, 33L, 60L, 51L)), .Names = c("pressure", "nfast", "nfailures"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame") # nfast is the sample size per covariate class, nfailures and pressure # the response and covariate, respectively. # Notice that the weights variable is the denominator of the response m <- glm(nfailures/nfast ~ pressure, data = ex4.7, weights = nfast) ex4.7a <- cbind(ex4.7, pred = predict(m, type = 'response')) # Check that the observed proportions and the predicted probabilities are reasonably in sync library(ggplot2) ggplot(ex4.7a, aes(x = pressure, y = nfailures/nfast)) + geom_point(size = 2.5) + geom_line(aes(y = pred), size = 1, color = 'red') # or in base graphics, plot(nfailures/nfast ~ pressure, data = ex4.7a, pch = 16) with(ex4.7a, lines(pressure, pred, col = 'red', lwd = 1.2)) HTH, Dennis On Sat, Dec 11, 2010 at 8:59 AM, Enrique Garcia <eckomo...@yahoo.com> wrote: > > Hello R folks, > > I have three questions. I am trying to run a logistic regression (binomial > family) where the response variable is a proportion. According to R > Documentation in "a binomial GLM prior weights are used to give the number > of trials when the response is the proportion of successes." However when > I > run my code I get the following error message: > > Error in model.frame.default(formula = PER_ELA ~ A_EX + COMM + ENG + S_R + > : > variable lengths differ (found for '(weights)') > > I'm not sure what I am doing wrong. My response variable is Y/M, which is > the proportion of 1's (successes) among M binary responses. My prior > weight > is a variable indicating the number of trials for each observation. > > > This is an abbreviated version of the code that I ran: > > glm1<-glm(PER_ELA~A_EX .... PER_LEA, > family=binomial(link="logit"),data=data2,weights="REG") > > > Question 1 and 2: > Does the number of trials for each observation in my dataset have to be the > same? What am I doing wrong here? > > > Question 3: > Is it OK for me to use percentages as predictor variables in a logistic > regression? > > -- > View this message in context: > http://r.789695.n4.nabble.com/Specifying-Prior-Weights-in-a-GLM-tp3083480p3083480.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.