[R] rms plot.Predict question: swapping x- and y- axis for categorical predictors

Frank Harrell f.harrell at vanderbilt.edu
Tue Oct 23 20:20:05 CEST 2012


Stephanie,

I just realized this is already implemented.  For your problem use p <-
Predict(f,x2); plot(p, ~ x2, nlines=TRUE)
Frank


Frank Harrell wrote
> Stephanie,
> 
> 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
> are using linux I can get you a new version of rms with this option as
> soon as 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.
> 
> Frank
> 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
>> x-axis. Is there a way to prevent this reversal?
>> 
>> Sample code with dummy data:
>> 
>> # make dummy data
>> set.seed(1)
>> 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)
>> options(datadist="d")
>> 
>> # 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))
>> function 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.
>> 
>> Best,
>> Stephanie
>> 
>> (Stanford University, Department of Linguistics)





-----
Frank Harrell
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-tp4646891p4647187.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list