I have a small question concerning the interpretation of a plot that
the Design package allows for logistic regression analyses
lets say we have a lrm-object that models a binary response as a
function of 3 binary predictors and call it "model"
now apparently, we can plot all logit-coefficients (turned back into
probabilities) for each level of each factor with
par(mfrow=c(1,3)) # cause we have 3 predictors
plot(model,fun=plogis, ylab="Pr(Y=1)",ylim=c(0,1))
# the crucial part is "fun=plogis"; we could also choose different
sclales, e.g. fun=exp for exponentiated logits...or logits
If I understand these plots correctly, they do in fact show Pr(Y=1|
factor_level_what_have_you)
Q1: Is this correct?
Q2: How does R know...nope, let me rephrase this...How can I get from
the changes in predicted probability (i.e. the values I get from
inv.logit(coefficients(model)) ) to these values?
(I guess the two questions are interrelated)
thanks in advance
-daniel
predict(some.model, newdata=...)
to get that predicted probability.
HTH,
STG
--
Stefan Th. Gries
-----------------------------------------------
University of California, Santa Barbara
http://www.linguistics.ucsb.edu/faculty/stgries
-----------------------------------------------
but I guess the formulation of my Q was a little clumsy;
let me see if I understand...
when I plot the effects w/
plot(model, fun=plogis, ylab="Pr(Y=1)", adj.subtitle= T)
I get to see the adjustments for each plot.
So I understand what I see in the plots is the transformed value of
"logit p", where
logit p = beta0 + beta1_level_1(of factor_1) + beta2_adjusted_level(of
factor_2) + ... + betak_adjusted_level(of factor_k)
right?
> the tricky (and sometimes treacherous) issue is
> that the plotted probabilities are often those that you find when
> other predictor variables are set to x
I understand that the adjustments are sometimes treacherous w/
continuous predictors.
But my problem can in fact be illustrated, when there is only 1
predictor.
It boils down to: How exactly do the values I get from
inv.logit(coefficients(model) [=the transformed logits] relate to the
Pr in the plot (or the output of predict.lrm() ) ?
Let me give an example: I have fit another model (model2) that
includes only one of my three predictors (for the sake of simplicity)
I can look at the transformed effect with
> inv.logit(coefficients(model2))
Intercept extern.height=ext.low
0.58880779 0.06452229
when I plot the model with
plot(model2, fun=plogis,...) # I get something like .59 for the level
"ext.low" (hard to read off the plot), so I apply
predict(model2, type="fitted.ind") # turns out the value is .588; and
the value for the complementary level is .089
all that is fine, but I dont understand how these values (.588, .089)
relate to the 0.06452229 above; or, to put it differently, what
exactly the value of inv.logit tells me...I was hoping it would be a
ratio of the two Pr ... but apparently it's not
all is good when I operate with "exp(coefficients)" and "plot(model2,
type= exp)" and then look at the predicted values (--> odds
ratio)...hold on *IT'S A BINGO*...or it might be...
is perhaps inv.logit(coefficients(model) = Pr(Y=1|levelA) / (1 +
Pr(Y=1|levelB) ? # that would make some sense ...
##### pasteable code: beginning
# set up
rm(list=ls(all=TRUE))
library(Design)
logit<-function(x) { log(x/(1-x)) }
ilogit<-function(x) { 1/(1+exp(-x)) }
# generate random data
set.seed(1) # homogenize random values across users
z<-data.frame(xxx=factor(sample(letters[1:3], 100, replace=TRUE)),
yyy=factor(sample(letters[1:2], 100, replace=TRUE))); attach(z)
example.dd<-datadist(z); options(datadist="example.dd")
# compute bin log regr.
model.lrm <- lrm(yyy ~ xxx, data=z, x=TRUE, y=TRUE,
linear.predictors=TRUE) # model
plot(model.lrm, fun=plogis, ylab="Pr(Y=1)", adj.subtitle=T) # from your mail
# see the predicted probability of yyy being "b" for each level of xxx
table(xxx, predict(model.lrm, type="fitted.ind"))
prediction.for.xxx.a <- ilogit(sum(model.lrm$coef[1])) # prediction
for when xxx is a
prediction.for.xxx.b <- ilogit(sum(model.lrm$coef[1:2])) # prediction
for when xxx is b
prediction.for.xxx.c <- ilogit(sum(model.lrm$coef[c(1, 3)])) #
prediction for when xxx is c
# when I type
locator(3)[[2]]
# and the click into the middle of the three points, I get the
following predicted probabilities / y-values
[1] 0.7040869 0.3948993 0.5714715
##### pasteable code: end
This seem to me to be reasonably close enough (giving mouse-pointing
inaccuracy) to the three predicted values ... can you tell us what the
problem is with these data?
Cheers,
logit(0.703703696627804)
to get the intercept: 0.8649.
And re the probability for the alphabetically second level, you type this:
logit(0.703703696627804)-logit(0.394736842105285) # intercept - prob of "b"
Etc.