[R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Dear friends, I am testing glm as at page 514/515 of THE R BOOK by M.Crawley, that is on proportion data. I use glm(y~x1+,family=binomial) y is a proportion in (0,1), and x is a real number. I get the error: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! But that is exactly what was suggested in the book, where there is no mention of a similar warning. Where am I going wrong? Here is the output: glm(response.prepared~x,data=,family=binomial) Call: glm(formula = response.prepared ~ x, family = binomial, data = ) Coefficients: (Intercept)x -0.3603 0.4480 Degrees of Freedom: 510554 Total (i.e. Null); 510553 Residual Null Deviance: 24420 Residual Deviance: 23240AIC: 700700 Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
A) It is not an error, only a warning. Wouldn't it seem reasonable to issue such a warning if you have data that violates the distributional assumptions? B) You did not include any of the data C) Wouldn't this be more appropriate to the author of the book if this is exactly what was suggested there? -- David, On Mar 30, 2010, at 10:51 AM, Corrado wrote: Dear friends, I am testing glm as at page 514/515 of THE R BOOK by M.Crawley, that is on proportion data. I use glm(y~x1+,family=binomial) y is a proportion in (0,1), and x is a real number. I get the error: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! But that is exactly what was suggested in the book, where there is no mention of a similar warning. Where am I going wrong? Here is the output: glm(response.prepared~x,data=,family=binomial) Call: glm(formula = response.prepared ~ x, family = binomial, data = ) Coefficients: (Intercept)x-0.3603 0.4480 Degrees of Freedom: 510554 Total (i.e. Null); 510553 Residual Null Deviance: 24420 Residual Deviance: 23240AIC: 700700 Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk __ 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. David Winsemius, MD West Hartford, CT __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
-Mensaje original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] En nombre de Corrado Enviado el: martes, 30 de marzo de 2010 16:52 Para: r-help@r-project.org Asunto: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Dear friends, I am testing glm as at page 514/515 of THE R BOOK by M.Crawley, that is on proportion data. I use glm(y~x1+,family=binomial) y is a proportion in (0,1), and x is a real number. I get the error: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! But that is exactly what was suggested in the book, where there is no mention of a similar warning. Where am I going wrong? Here is the output: glm(response.prepared~x,data=,family=binomial) Call: glm(formula = response.prepared ~ x, family = binomial, data = ) Coefficients: (Intercept)x -0.3603 0.4480 Degrees of Freedom: 510554 Total (i.e. Null); 510553 Residual Null Deviance: 24420 Residual Deviance: 23240AIC: 700700 Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk --- Probably you are misreading Crawley's Book? A proportion would usually be modeled with the Beta distribution, not the binomial, which is for counts. If you are modeling a proportion try the betareg function in betareg package. HTH Ruben Dr. Rubén Roa-Ureta AZTI - Tecnalia / Marine Research Unit Txatxarramendi Ugartea z/g 48395 Sukarrieta (Bizkaia) SPAIN __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
In a Binomial GLM, typically y is a factor with two levels (indicating success/failure) instead of a numeric vector on [0, 1]. Perhaps the description in the book is not so clear. You should interpret data on proportions as the observations from a Binomial distribution (rather than we observed some proportion data which fell in [0,1]). E.g. y=rbinom(10, size = 1, prob = .3); x=rnorm(y) # or y = factor(y) glm(y~x, family = binomial) Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-6609 Web: http://yihui.name Department of Statistics, Iowa State University 3211 Snedecor Hall, Ames, IA On Tue, Mar 30, 2010 at 9:51 AM, Corrado ct...@york.ac.uk wrote: Dear friends, I am testing glm as at page 514/515 of THE R BOOK by M.Crawley, that is on proportion data. I use glm(y~x1+,family=binomial) y is a proportion in (0,1), and x is a real number. I get the error: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! But that is exactly what was suggested in the book, where there is no mention of a similar warning. Where am I going wrong? Here is the output: glm(response.prepared~x,data=,family=binomial) Call: glm(formula = response.prepared ~ x, family = binomial, data = ) Coefficients: (Intercept) x -0.3603 0.4480 Degrees of Freedom: 510554 Total (i.e. Null); 510553 Residual Null Deviance: 24420 Residual Deviance: 23240 AIC: 700700 Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk __ 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. __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Dear David, David Winsemius wrote: A) It is not an error, only a warning. Wouldn't it seem reasonable to issue such a warning if you have data that violates the distributional assumptions? I am not questioning the approach. I am only trying to understand why a (rather expensive) source of documentation and the behaviour of a function are not aligned. B) You did not include any of the data Data attached as R object. C) Wouldn't this be more appropriate to the author of the book if this is exactly what was suggested there? I think it will be definitively appropriate, but only when I am certain I am not doing anything wrong. Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Dear Ruben I am afraid not the paragraph's title is a bit of a give away: Proportion Data and Binomial Errors The sentence reads: are dealt with by using a generalised linear model with a binomial error structure. with the example: glm(y~x,family=binomial) You can check at page 514/515. Rubén Roa wrote: -Mensaje original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] En nombre de Corrado Enviado el: martes, 30 de marzo de 2010 16:52 Para: r-help@r-project.org Asunto: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Dear friends, I am testing glm as at page 514/515 of THE R BOOK by M.Crawley, that is on proportion data. I use glm(y~x1+,family=binomial) y is a proportion in (0,1), and x is a real number. I get the error: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! But that is exactly what was suggested in the book, where there is no mention of a similar warning. Where am I going wrong? Here is the output: glm(response.prepared~x,data=,family=binomial) Call: glm(formula = response.prepared ~ x, family = binomial, data = ) Coefficients: (Intercept)x -0.3603 0.4480 Degrees of Freedom: 510554 Total (i.e. Null); 510553 Residual Null Deviance: 24420 Residual Deviance: 23240AIC: 700700 Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
On Mar 30, 2010, at 11:19 AM, Corrado wrote: Dear David, David Winsemius wrote: A) It is not an error, only a warning. Wouldn't it seem reasonable to issue such a warning if you have data that violates the distributional assumptions? I am not questioning the approach. I am only trying to understand why a (rather expensive) source of documentation and the behaviour of a function are not aligned. B) You did not include any of the data Data attached as R object. C) Wouldn't this be more appropriate to the author of the book if this is exactly what was suggested there? I think it will be definitively appropriate, but only when I am certain I am not doing anything wrong. I don't understand this perspective. You bought Crowley's book so he is in some minor sense in debt to you. Why should you think it is more appropriate to send your message out to thousands of readers of r- help around the world (some of whom have written books that you did not buy) before sending Crowley a question about his text? Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk David Winsemius, MD West Hartford, CT __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
G'day all, On Tue, 30 Mar 2010 16:19:46 +0100 Corrado ct...@york.ac.uk wrote: David Winsemius wrote: A) It is not an error, only a warning. Wouldn't it seem reasonable to issue such a warning if you have data that violates the distributional assumptions? I am not questioning the approach. I am only trying to understand why a (rather expensive) source of documentation and the behaviour of a function are not aligned. 1) Also expensive books have typos in them. 2) glm() is from a package that is part of R and the author of this book is AFAIK not a member of R core, hence has no control on whether his documentation and the behaviour of a function are aligned. a) If he were documenting a function that was part of a package he wrote as support for his book, as some authors do, there might be a reason to complain. But then 1) would still apply. b) Even books written by members of R core have occasionally misalignments between the behaviour of a function and the documentation contained in such books. This can be due to them documenting a function over whose implementation they do not have control (e.g. a function in a contributed package) or the fact that R is improving/changing from version to version while books are rather static. For these reasons it is always worthwhile to check the errata page for a book, if such exists. The source of the warning is due to the fact that you do not provide all necessary information about your response. If your response is binomial (with a mean depended on some explanatory variables), then each response consists of two numbers, the number of trials and the number of success. If you calculate the observed proportion of successes from these two numbers and feed this into glm as the response, you are omitting necessary information. In this case, you should provide the number of trials on which each proportion is based as prior weights. For example: R x - seq(from=-1,to=1,length=41) R px - exp(x)/(1+exp(x)) R nn - sample(8:12, 41, replace=TRUE) R yy - rbinom(41, size=nn, prob=px) R y - yy/nn R glm(y~x, family=binomial, weights=nn) Call: glm(formula = y ~ x, family = binomial, weights = nn) Coefficients: (Intercept)x 0.2461.124 Degrees of Freedom: 40 Total (i.e. Null); 39 Residual Null Deviance: 91.49 Residual Deviance: 50.83AIC: 157.6 R glm(y~x, family=binomial) Call: glm(formula = y ~ x, family = binomial) Coefficients: (Intercept)x 0.2143 1.1152 Degrees of Freedom: 40 Total (i.e. Null); 39 Residual Null Deviance: 9.256 Residual Deviance: 5.229AIC: 49.87 Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! HTH, Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019)+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: ber...@maths.uwa.edu.au Australiahttp://www.maths.uwa.edu.au/~berwin __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Corrado I am afraid not the paragraph's title is a bit of a give away: Proportion Data and Binomial Errors The sentence reads: are dealt with by using a generalised linear model with a binomial error structure. with the example: glm(y~x,family=binomial) You can check at page 514/515. It would be better to check Chapter 16 (from page 569) on Proportions. The pages you cite don't come across to me as an example of how this procedure should be carried out, but rather a trivial example on the changes in syntax between a linear model and a GLM. Graham __ 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.
Re: [R] From THE R BOOK - Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
At 12:08 PM 3/30/2010, David Winsemius wrote: snip I don't understand this perspective. You bought Crowley's book so he is in some minor sense in debt to you. Why should you think it is more appropriate to send your message out to thousands of readers of r- help around the world (some of whom have written books that you did not buy) before sending Crowley a question about his text? In fairness to Michael Crawley, whose books are useful and very clear (although not well-liked on this list for some reason): 1. The example quoted by Corrado Topi is not an actual example. Instead is an isolated line of code given to illustrate the simplicity of glm() syntax and its relation to lm() syntax. This is in a short general topic overview chapter on GLMs meant to introduce concepts and terminology, not runnable code. 2. The example chapter is followed in the book by individual chapters on each type of GLM covered (count data, count data in tables, proportion data, binary response variables). If Corrado Topi had looked in the relevant chapter, he would find numerous worked out examples with runnable code. Corrado Topi made an error in trying to run an isolated line of code without antecedent definitions, which almost never works in any programming system. Michael Crawley made a mistake in judgment in assuming that detail later will suffice for generality now. My advice to Corrado Topi is engage in some forward referencing, and read chapters 16 and 17 before deciding which example code to run. Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: r...@lcfltd.com Least Cost Formulations, Ltd.URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239Fax: 757-467-2947 Vere scire est per causas scire __ 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.