[R] indicator or deviation contrasts in log-linear modelling

Charles C. Berry cberry at tajo.ucsd.edu
Thu Feb 19 18:06:32 CET 2009


On Wed, 18 Feb 2009, maiya wrote:

>
> I realise that in the case of loglin the parameters are clacluated post
> festum from the cell frequencies,
> however other programmes that use Newton-Raphson as opposed to IPF work the
> other way round, right?
> In which case one would expect the output of parameters to be limited to the
> particular contrast used. But since loglin uses IPF I would have thought the
> choice of style of parameter to be output could be made...
> Anyway, this is the line that interests me:
>
>> 	lm( as.vector( loglin(...,fit=TRUE)$fit ) ~ < your favored contrasts > )
>
> only I'm not profficient in R to figure out the last term :(
> How would I go about this then if my prefered contrasti is setting the first
> categories as reference cats?

See	An Introduction to R Chapter 11

and try this:


  for ( i in ls('package:stats',pat='contr[.]')){
  cat( i, '\n' )
  print( get(i)(letters[1:5]) )
  options(contrasts=c(unordered=i,ordered='contr.poly'))
  print( coef( glm( Freq~ Dept*Gender,
 	as.data.frame(UCBAdmissions),family=poisson)) )
  }


>
> I literaly just need the equivalent of
>
> loglin(matrix(c(1,2,3,4), nrow=2), list(c(1,2)), param=TRUE)
>
> which would give me parameters under indicator contrast. glm... well, I'd
> have to work on it
>
> Regarding the more general points
>
> ad 2) I would have thought that direct inspection of cell frequencies is
> precisely the wrong/misleading thing to do - the highest order coefficients
> can be inspected directly in order to see the interaction without the
> (lower) marginal effects, or alternatively the table can be standardized to
> uniform margins for the same sort of inspection.

OK, to each her own.

But try this out yourself. What is the story here?

(Review ?UCBAdmissions, if you need to.)

> options(contrasts=c(unordered='contr.sum',ordered='contr.poly'))
> print( cbind(coef( glm( Freq~ Admit*Dept*Gender,
   as.data.frame(UCBAdmissions),family=poisson)) ))
                              [,1]
(Intercept)           4.786575880
Admit1               -0.277614562
Dept1                 0.067824911
Dept2                -0.758615446
Dept3                 0.560293364
Dept4                 0.446131873
Dept5                -0.001254892
Gender1               0.355262130
Admit1:Dept1          0.786694268
Admit1:Dept2          0.599494828
Admit1:Dept3         -0.021374963
Admit1:Dept4         -0.053867688
Admit1:Dept5         -0.250913079
Admit1:Gender1       -0.050744703
Dept1:Gender1         0.782600986
Dept2:Gender1         1.216370861
Dept3:Gender1        -0.646880514
Dept4:Gender1        -0.308737151
Dept5:Gender1        -0.691810320
Admit1:Dept1:Gender1 -0.212274286
Admit1:Dept2:Gender1 -0.004260932
Admit1:Dept3:Gender1  0.081975109
Admit1:Dept4:Gender1  0.030247904
Admit1:Dept5:Gender1  0.100791458
>

OK, got the whole story? Could you explain it to someone who is not a 
statistician?

Now try it again. But with this display:

> ftable(UCBAdmissions)
                 Dept   A   B   C   D   E   F
Admit    Gender
Admitted Male        512 353 120 138  53  22
          Female       89  17 202 131  94  24
Rejected Male        313 207 205 279 138 351
          Female       19   8 391 244 299 317
> round( ftable(prop.table(UCBAdmissions,2:3)) ,2)
                 Dept    A    B    C    D    E    F
Admit    Gender
Admitted Male        0.62 0.63 0.37 0.33 0.28 0.06
          Female      0.82 0.68 0.34 0.35 0.24 0.07
Rejected Male        0.38 0.37 0.63 0.67 0.72 0.94
          Female      0.18 0.32 0.66 0.65 0.76 0.93


You can pretty easily see that admission rates vary by department, that 
all departments but one have pretty equal admission rates by gender and 
that in that department the rate is a 20% higher for females. (And yes, 
a significance test confirms this).

Maybe not a "statistified" as talking about three-way interactions and 
coefficients of products of contrasts, but I'll bet a lot of scientists 
would find the tables more compelling.

HTH,

Chuck

>
> ad 3) and yes, I figured as much! I can't see how lower order terms can be
> interpreted at all if higher order interactions exist? I've seen it done,
> e.g I've seen it claimed that in a standardized table the lower order terms
> are all equal to zero, which is of course not true?
>
> Thanks!
> Maja
>
>
>
> -- 
> View this message in context: http://www.nabble.com/indicator-or-deviation-contrasts-in-log-linear-modelling-tp22090104p22093070.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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901




More information about the R-help mailing list