Dylan Beaudette
2009-Oct-26 17:55 UTC
[R] Cbind() on the right-side of a formula in xYplot()
Hi, Using the latest rms package I am able to make nice plots of model predictions +/- desired confidence intervals like this: # need this library(rms) # setup data d <- data.frame(x=rnorm(100), y=rnorm(100)) dd <- datadist(d) options(datadist='dd') # fit model l <- ols(y ~ rcs(x), data=d) # predict along original limits of data l.pred <- Predict(l) # plot of fit and conf. int. xYplot(Cbind(yhat, lower, upper) ~ x, data=l.pred, method='filled', col.fill=grey(0.9), col=1, type='l') Is there any way in which I can turn this figure on its side, by plotting x ~ y... something like this: # doesn't work xYplot(x ~ Cbind(yhat, lower, upper), data=l.pred, method='filled', lable.curves=FALSE, col.fill=grey(0.9), col=1, type='l') # standard lattice, but without the fancy filled area xyplot(x ~ yhat + lower + upper, data=l.pred, type='l', lty=c(1,2,2), col=1) Any suggestions? If it is not possible, then I will try and manually make the figure with basic lattice functions. Cheers, Dylan -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341
Frank E Harrell Jr
2009-Oct-26 18:23 UTC
[R] Cbind() on the right-side of a formula in xYplot()
Dylan Beaudette wrote:> Hi, > > Using the latest rms package I am able to make nice plots of model predictions > +/- desired confidence intervals like this: > > # need this > library(rms) > > # setup data > d <- data.frame(x=rnorm(100), y=rnorm(100)) > dd <- datadist(d) > options(datadist='dd') > > # fit model > l <- ols(y ~ rcs(x), data=d) > > # predict along original limits of data > l.pred <- Predict(l) > > # plot of fit and conf. int. > xYplot(Cbind(yhat, lower, upper) ~ x, data=l.pred, method='filled', > col.fill=grey(0.9), col=1, type='l') > > Is there any way in which I can turn this figure on its side, by plotting x ~ > y... something like this: > > # doesn't work > xYplot(x ~ Cbind(yhat, lower, upper), data=l.pred, method='filled', > lable.curves=FALSE, col.fill=grey(0.9), col=1, type='l') > > # standard lattice, but without the fancy filled area > xyplot(x ~ yhat + lower + upper, data=l.pred, type='l', lty=c(1,2,2), col=1) > > Any suggestions? If it is not possible, then I will try and manually make the > figure with basic lattice functions. > > Cheers, > Dylan > >Dylan, Cbind is for the left hand side of the formula. I suggest you look at one of the books that covers lattice graphics, or the online resources for lattice to customize this. The output from Predict is suitable for several graphics models. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University