[R] rms plot.Predict question: swapping x- and y- axis for categorical predictors
f.harrell at vanderbilt.edu
Tue Oct 30 20:29:37 CET 2012
The new version of rms is now on CRAN (for Mac and Windows probably
tomorrow). You can now do p <- Predict(...); plot(p, ~ x2, nlines=TRUE,
type='p') to get what you want.
> Hi Frank,
> Thanks for your reply! Using p <- Predict(f, x2); plot(p, ~x2,
> makes a categorical predictor (x2, with two levels) look like a continuous
> one. Is there a way to only use dots (error margins), and no continuous
> line between the predictor values (as with p <- Predict(f, x2); plot(p),
> except with the axes reversed)?
> On Tue, Oct 23, 2012 at 11:20 AM, Frank Harrell [via R] <
> ml-node+s789695n4647187h22 at .nabble
>> I just realized this is already implemented. For your problem use p <-
>> Predict(f,x2); plot(p, ~ x2, nlines=TRUE)
>> Frank Harrell wrote
>> I'm working on an option for the plot method for Predict that will allow
>> you to do this. Note that this approach will not result in very readable
>> predictor category labels when they are long character strings. If you
>> using linux I can get you a new version of rms with this option as soon
>> I've finished it, otherwise I can give you a workaround using source( ).
>> If you don't hear from me in a few days please write back.
>> stephsus wrote
>> Hello all,
>> I'm trying to plot the effects of variables estimated by a regression
>> model fit individually, and for categorical predictors, the independent
>> variable shows up on the y-axis, with the dependent variable on the
>> Is there a way to prevent this reversal?
>> Sample code with dummy data:
>> # make dummy data
>> x1 <- runif(200)
>> x2 <- sample(c(1,2),200, TRUE)
>> x3 <- sample(c(0,1),200,T)
>> x4 <- runif(200)
>> # the dependent variable:
>> distance <- (x1/3 + x2 + rnorm(200)^2 - x3 - x4/2)
>> # factor two vars, and add to datadist:
>> x3 <- factor(x3)
>> x2 <- factor(x2)
>> d <- datadist(x1,x2,x3,x4)
>> # Make a simple model:
>> f <- ols(distance ~ x1 + x2 + x4+ x3, x=T)
>> # plot variable effect of a categorical variable:
>> plot(Predict(f, x2))
>> ^ above step generates a plot with x2 on the y-axis and distance on the
>> x-axis, which is the opposite of what I'm aiming for. The continuous
>> variables do not have this problem; nor does the plot(Predict(f))
>> to plot all of the effects at once.
>> Thank you so much in advance for your replies! My apologies if this
>> question has been answered already; I've tried searching to no avail.
>> (Stanford University, Department of Linguistics)
>> Frank Harrell
>> Department of Biostatistics, Vanderbilt University
>> If you reply to this email, your message will be added to the discussion
>> To unsubscribe from rms plot.Predict question: swapping x- and y- axis
>> for categorical predictors, click
> Stephanie Sin-yun Shih
> Ph.D. candidate
> Department of Linguistics
> Stanford University
Department of Biostatistics, Vanderbilt University
View this message in context: http://r.789695.n4.nabble.com/rms-plot-Predict-question-swapping-x-and-y-axis-for-categorical-predictors-tp4646891p4647928.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help