[R] Estimate of intercept in loglinear model
Mark Difford
mark_difford at yahoo.co.uk
Tue Nov 8 19:58:59 CET 2011
On Nov 08, 2011 at 11:16am Colin Aitken wrote:
> An unresolved problem is: what does R do when the explanatory factors
> are not defined as factors when it obtains a different value for the
> intercept but the correct value for the fitted value?
Colin,
I don't think that happens (that the fitted values are identical if
predictors are cast as numerical), but the following could (really is
answered by my initial answer). Once again, using the example I gave above,
but using the second level of "outcome" as a reference level for a new fit,
called glm.D93R. (For this part of the question a corpse would have been
nice, though not really needed---"yours" was unfortunately buried too deeply
for me to find it,)
## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
glm.D93R <- glm(counts ~ C(outcome, base=2) + treatment, family=poisson())
## treat predictor as numeric
glm.D93N <- glm(counts ~ as.numeric(as.character(outcome)) +
as.numeric(as.character (treatment)), family=poisson())
> coef(glm.D93)
(Intercept) outcome2 outcome3 treatment2 treatment3
3.044522e+00 -4.542553e-01 -2.929871e-01 1.337909e-15 1.421085e-15
## Different value for the Intercept but same fitted values (see below) as
the earlier fit (above)
##
summary(glm.D93R)
< snipped and edited for clarity>
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.590e+00 1.958e-01 13.230 <2e-16 ***
outcome1 4.543e-01 2.022e-01 2.247 0.0246 *
outcome3 1.613e-01 2.151e-01 0.750 0.4535
treatment2 -3.349e-16 2.000e-01 0.000 1.0000
treatment3 -6.217e-16 2.000e-01 0.000 1.0000
< snip >
> fitted(glm.D93)
1 2 3 4 5 6 7 8
9
21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 21.00000 13.33333
15.66667
> fitted(glm.D93R)
1 2 3 4 5 6 7 8
9
21.00000 13.33333 15.66667 21.00000 13.33333 15.66667 21.00000 13.33333
15.66667
## if predictors treated as numeric---check summary(glm.D93N) yourself
> fitted(glm.D93N)
1 2 3 4 5 6 7 8
9
19.40460 16.52414 14.07126 19.40460 16.52414 14.07126 19.40460 16.52414
14.07126
Regards, Mark.
-----
Mark Difford (Ph.D.)
Research Associate
Botany Department
Nelson Mandela Metropolitan University
Port Elizabeth, South Africa
--
View this message in context: http://r.789695.n4.nabble.com/Estimate-of-intercept-in-loglinear-model-tp4009905p4017091.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list