[R] A Contrast Question

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Jan 10 22:33:58 CET 2008


Hi Folks,
This should have been simple to answer,
but despite much chasing I don't seem able
to catch this particular mouse!

Basically (somewhat simplified): I have a
binary response variable Y (0/1) and a
2-level factor A (0/1).

I want to assign a contrast to A such that,
when I run

summary(glm(Y~A, family=binomial))$coef

the Intercept coefficient is the result that
I would get from running glm(Y ~ 1), and
the "A" coefficient is the log(odds ratio)
of the "A=1" results relative to all the data.

Explicitly: if p = sum(Y==1)/length(Y),
and p1 = sum(Y[A==1]==1)/length(Y[A==1])
then:

Intercept:  log(p/(1-p))

Coeff of A: log((p1/(1-p1))/(p/(1-p)))

(The objective is to assess whether a covariate
that may result in only observing a subset of
the data would produce a significant selection
bias in the result).

I know I could derive the result from manipulation
of the output from a standard contrast function,
but I would prefer to delegate it all (including
calculation of SE and P-value) to a run of glm().

With thanks,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 10-Jan-08                                       Time: 21:33:53
------------------------------ XFMail ------------------------------




More information about the R-help mailing list