Maybe try making sure the data is numeric: fac.to.num=function(x) as.numeric(as.character(x))
On 26-Jul-07, at 9:34 AM, Sullivan, Mary M wrote: > Greetings, > > > I am working on a logistic regression model in R and I am > struggling with the code, as it is a relatively new program for > me. In searching Google for 'logistic regression diagnostics' I > came Elizabeth Brown's Lecture 14 from her Winter 2004 > Biostatistics 515 course (http://courses.washington.edu/b515/ > l14.pdf) . I found most of the code to be very helpful, but I am > struggling with the lines on to calculate the observed and expected > values in the 10 groups created by the cut function. I get error > messages in trying to create the E and O matrices: R won't accept > assignment of "fi1c==j" and it won't calculate the sum. > > > > I am wondering whether someone might be able to offer me some > assistance...my search of the archives was not fruitful. > > > > Here is the code that I adapted from the lecture notes: > > > > fit <- fitted(glm.lyme) > > fitc <- cut(fit, br = c(0, quantile(fit, p = seq(.1, .9, .1)),1)) > > t<-table(fitc) > > fitc <- cut(fit, br = c(0, quantile(fit, p = seq(.1, .9, .1)), 1), > labels = F) > > t<-table(fitc) > > > > #Calculate observed and expected values in ea group > > E <- matrix(0, nrow=10, ncol = 2) > > O <- matrix(0, nrow=10, ncol=2) > > for (j in 1:10) { > > E[j, 2] = sum(fit[fitc==j]) > > E[j, 1] = sum((1- fit)[fitc==j]) > > O[j, 2] = sum(pcdata$lymdis[fitc==j]) > > O[j, 1] = sum((1-pcdata$lymdis)[fitc==j]) > > > > } > > > > Here is the error message: Error in Summary.factor(..., na.rm = > na.rm) : > sum not meaningful for factors > > > > > > I understand what it means; I just can't figure out how to get > around it or how to get the output printed in table form. Thank > you in advance for any assistance. > > > > Mary Sullivan > > ______________________________________________ > R-help@stat.math.ethz.ch 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. -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public "The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less." - Piet Hein ______________________________________________ R-help@stat.math.ethz.ch 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.