[R] GLM Help

Weidong Gu anopheles123 at gmail.com
Sat Oct 29 00:32:15 CEST 2011


Are you sure your variables are categorical or numeric? Of course, glm
differentiates these two kinds of variables. For example, I ran the
same variable with different modes, the results are very different.

> dat<-data.frame(y=rpois(100,5),xf=as.factor(sample(1:4,100,replace=T)))
> glm(y~xf,data=dat,family=poisson)

Call:  glm(formula = y ~ xf, family = poisson, data = dat)

Coefficients:
(Intercept)          xf2          xf3          xf4
    1.60944     -0.12783     -0.11878     -0.09746

...
> glm(y~as.numeric(xf),data=dat,family=poisson)

Call:  glm(formula = y ~ as.numeric(xf), family = poisson, data = dat)

Coefficients:
   (Intercept)  as.numeric(xf)
       1.59047        -0.02673


Weidong Gu


On Fri, Oct 28, 2011 at 4:21 PM, CES <smit4155 at umn.edu> wrote:
> Hey all,
>
>  I am attempting to replicate my results achieved in another program within
> R (so I can expand my options for methods). I am trying to run a GLM (Family
> = Poisson) for count data in R. Some of my variables are factors and I am
> under the impression that the function glm() cannot run a model with Poisson
> dist and factors??
>
> Here is why I think this, if I run two models using glm(), one treating a
> variable (e.g., Harvest.Factor) as a Factor and the other treating a
> variable as continuous (e.g., Harvest.Cont) I get the same results in R.
>
> Is there a package that will allow me to run a GLM using a Poisson dist and
> factor variables?
>
> Thanks for any help!
> -Chris
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/GLM-Help-tp3949104p3949104.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list