[R] rms plot.Predict question: swapping x- and y- axis for categorical predictors
stephsus at gmail.com
Sun Oct 21 01:26:53 CEST 2012
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
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:
^ 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.
(Stanford University, Department of Linguistics)
View this message in context: http://r.789695.n4.nabble.com/rms-plot-Predict-question-swapping-x-and-y-axis-for-categorical-predictors-tp4646891.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help