[R] GLM for logistic regression and WEIGHTS
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Mar 28 22:58:18 CEST 2004
There is no restriction to integer weights in R. Here is a (silly)
example.
library(MASS)
fit1 <- glm(cbind(pm.y, pm.tot - pm.y) ~ density, binomial, data=rotifer)
wt <- runif(20)
update(fit1, weights=wt)
or
glm(pm.y/pm.tot ~ density, binomial, data=rotifer, weights=pm.tot)
glm(pm.y/pm.tot ~ density, binomial, data=rotifer, weights=pm.tot*wt)
which gives an harmless warning (not an error message).
I use this sort of thing for multiple imputation quite frequently.
On Sun, 28 Mar 2004, Marie-Pierre Sylvestre wrote:
> Hi all,
>
> I want to use weights for a logistic regression. In SAS, all I have to
> do is to specify my weight vector (they are fractions) and use proc
> logistic on my binary output.
That is all you do in R, too. See the example above.
> When I tried to do the same in R, I got an error message because my
> weights were not integer.
Please read the posting guide and supply a reproducible example of how you
got an *error* message here.
> I understand that the weight option in R is to
> be used when the dependent variable is a proportion so that the weight
> is the total from which this proportion is derived.
You `understand' incorrectly. Are you familiar with the theory of
generalized linear models -- weights are part of the definition of a glm?
> So what should I do if I want to use logistic regression but want to use
> weight to give more importance to certain observations (e.g.
> weight=0.87) and less to others (e.g. weight=.45) ? Should I
> reparametrize everything in terms of counts or is there an easier way
> out?
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list