The estimated coefficients would be the same subject to the condition that you create your dummy variables (i.e. the numerical ones) consistent to R. For example: lets' create a fake data and fit a Poisson glm using factor. Note that gl
function creates a factor variable.
> counts <- c(18,17,15,20,10,20,25,13,12)
> outcome <- gl(3,1,9)
> outcome
[1] 1 2 3 1 2 3 1 2 3
Levels: 1 2 3
> class(outcome)
[1] "factor"
> glm.1<- glm(counts ~ outcome, family = poisson())
> summary(glm.1)
Call:
glm(formula = counts ~ outcome, family = poisson())
Deviance Residuals:
Min 1Q Median 3Q Max
-0.9666 -0.6713 -0.1696 0.8471 1.0494
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.0445 0.1260 24.165 <2e-16 ***
outcome2 -0.4543 0.2022 -2.247 0.0246 *
outcome3 -0.2930 0.1927 -1.520 0.1285
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 10.5814 on 8 degrees of freedom
Residual deviance: 5.1291 on 6 degrees of freedom
AIC: 52.761
Number of Fisher Scoring iterations: 4
Since outcome has three levels, I create two dummy variables (dummy.1=0 if outcome=2
and dummy.2=1 if outcome=3) and refit using these numerical values:
> dummy.1=rep(0,9)
> dummy.2=rep(0,9)
> dummy.1[outcome==2]=1
> dummy.2[outcome==3]=1
> glm.2<- glm(counts ~ dummy.1+dummy.2, family = poisson())
> summary(glm.2)
Call:
glm(formula = counts ~ dummy.1 + dummy.2, family = poisson())
Deviance Residuals:
Min 1Q Median 3Q Max
-0.9666 -0.6713 -0.1696 0.8471 1.0494
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.0445 0.1260 24.165 <2e-16 ***
dummy.1 -0.4543 0.2022 -2.247 0.0246 *
dummy.2 -0.2930 0.1927 -1.520 0.1285
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 10.5814 on 8 degrees of freedom
Residual deviance: 5.1291 on 6 degrees of freedom
AIC: 52.761
Number of Fisher Scoring iterations: 4
As you can see the estimated coefficients are the same. But you need to be careful when creating your dummy variables if you want to get the same result. For example if I create two dummy variables as (dummy.1=0 if outcome=1 and dummy.2=1 if outcome=2) then the estimated results are different as follow:
> dummy.1=rep(0,9)
> dummy.2=rep(0,9)
> dummy.1[outcome==1]=1
> dummy.2[outcome==2]=1
> glm.3<- glm(counts ~ dummy.1+dummy.2, family = poisson())
> summary(glm.3)
Call:
glm(formula = counts ~ dummy.1 + dummy.2, family = poisson())
Deviance Residuals:
Min 1Q Median 3Q Max
-0.9666 -0.6713 -0.1696 0.8471 1.0494
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.7515 0.1459 18.86 <2e-16 ***
dummy.1 0.2930 0.1927 1.52 0.128
dummy.2 -0.1613 0.2151 -0.75 0.453
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 10.5814 on 8 degrees of freedom
Residual deviance: 5.1291 on 6 degrees of freedom
AIC: 52.761
Number of Fisher Scoring iterations: 4
This is because when you add outcome
variable in glm.1, R by default creates two dummy variables namely outcome2
and outcome3
and defines them similarly to dummy.1
and dummy.2
in glm.2 i.e. the first level of outcome is when all other dummy variables (outcome2
and outcome3
) are set to be zero.