[R] question on jitter in plot.Predict in rms

Frank Harrell f.harrell at vanderbilt.edu
Tue May 1 16:10:55 CEST 2012


Mike,

Try plot(pref, ..., scat1d.opts=list(frac=0.025, lwd=0.3, nhistSpike=i))

where i = 1 to always use spike histograms (default is to use them if n >=
2000) or i=1e7 to never use them and to always jitter instead.  There are
many other scat1d options you can pass through scat1d.opts.

Frank



Mike Babyak wrote
> 
> Dear colleagues,
> 
> I have a question regarding controlling the jitter when plotting
> predictions in the rms package.  Below I've simulated some data that
> reflect what I'm working with.  The model predicts a continuous variable
> with an ordinal score, a two-level group, and a continuous covariate.  Of
> primary interest is a plot of the group by score interaction, where the
> score is the ordinal variable, and the group Ns are quite disparate.
> 
> When I produce the plot for the predicted values with the data=llist
> argument, as expected I get datadensity hatch marks.  However, in the
> group
> with the smaller N, I get jittered datadensity points, while in the group
> with the larger N, the jitter apparently defaults to single vertical
> lines,
> which I assume is because the jitter would look like a black blob.  Some
> of
> my co-authors are a bit worried about how that looks, so here I am.
> 
> Apart from abandoning data=llist altogether, is there a way to modify the
> jitter in the smaller group so it behaves like the larger one?
> 
> Of secondary importance, anything you can tell me about improving my
> clumsy
> little simulation code would be welcome--I have little to no idea what I'm
> doing there.  for example, would there be a way to produce the group
> variable with the disparate Ns more directly?
> 
> Thanks,
> 
> Mike Babyak
> Behavioral Medicine Research Center
> Duke University Medical Center
> 
> 
> 
> #question about jitter/llist in rms
> #R v 2.14.1 under windows 7
> ####################################################################
> 
> #question about jitter/llist in rms
> require(rms)
> #simulate some data
> n     = 5000
> age   = runif(n)
> score = runif(n) + 0.5*age
> group<- as.numeric(sample(c(FALSE,TRUE), 5000, replace=T, prob=c(.1, .9)))
> ordscore = as.numeric(factor(rep(1:5, length.out=n)))
> table(group,ordscore)
> e     = rnorm(n, 0, 0.1)
> 
> #true model
> y     = group + 0.6*ordscore + group*ordscore  + .2*age + e
> 
> #convert group to factor
> group.f<-as.factor(group)
> 
> #save data characterics
> dd1<-datadist(age,ordscore,group.f)
> options(datadist="dd1")
> 
> #estimate model
> reg1<-ols(y~group.f+ordscore+group.f*ordscore+age,x=T,y=T)
> 
> #plot results
> preg<-Predict(reg1,ordscore,group.f)
> 
> #produces interaction plot with datadensity hatch marks
> plot(preg,data=llist(ordscore,group.f))
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@ mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-----
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: http://r.789695.n4.nabble.com/question-on-jitter-in-plot-Predict-in-rms-tp4598555p4600795.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list