It seems you have a two-way cross table with 10 levels of factor w
and 5 levels of factor s
with no interactions in the model. With glm()
, the default coding scheme for categorical variables is treatment coding where the first group in a factor is the reference level, and the respective parameter of each remaining group is its difference to this reference. The (Intercept)
estimate is for the cell with all groups = reference level for their factor.
With loglm()
, the parameters are for deviation coding, meaning that each group gets its own parameter, and the parameters for one factor sum to zero. (Intercept)
is the grand mean that gets added to all group effects.
In your example, you could tell glm()
to use deviation coding to get the same parameter estimates as with loglm()
(see below for an example), or you convert the parameter estimates from treatment coding as follows:
w
= 0.05 ands
= 2 is the reference cell:glm()
9.5104005 =loglm()
10.18939 + -1.04596513 + 0.36697307w
= 0.1 ands
= 2 is reference level fors
but needs the difference fromw
= 0.1 to the referencew
= 0.05:glm()
9.5104005 + 0.6340290 =loglm()
10.18939 + -0.41193617 + 0.36697307w
= 0.1 ands
= 3 but needs the difference fromw
= 0.1 to the referencew
= 0.05 and the difference froms
= 3 to the references
= 2:glm()
9.5104005 + 0.6340290 + -0.2153295 =loglm()
10.18939 + -0.41193617 + 0.15164360, and so on
Example with glm()
using deviation coding (UCBAdmissions
is a cross-table with absolute frequencies built into base R):
> library(MASS) # for loglm()
> llmFit <- loglm(~ Admit + Gender + Dept, data=UCBAdmissions)
> coef(llmFit)
$`(Intercept)`
[1] 5.177567
$Admit
Admitted Rejected
-0.2283697 0.2283697
$Gender
Male Female
0.1914342 -0.1914342
$Dept
A B C D E F
0.23047857 -0.23631478 0.21427076 0.06663476 -0.23802565 -0.03704367
> UCBdf <- as.data.frame(UCBAdmissions) # convert to data frame for glm()
> glmFit <- glm(Freq ~ Admit + Gender + Dept, family=poisson(link="log"),
+ contrasts=list(Admit=contr.sum, Gender=contr.sum, Dept=contr.sum),
+ data=UCBdf)
> coef(glmFit)
(Intercept) Admit1 Gender1 Dept1 Dept2 Dept3 Dept4
5.17756677 -0.22836970 0.19143420 0.23047857 -0.23631478 0.21427076 0.06663476
Dept5
-0.23802565
Note that glm()
does not list those parameter estimates that are fully determined (aliased) through the sum-to-zero constraint for the parameters for one factor.