Skip to content

Plotting every probability curve

2 messages · Abraham Mathew, Greg Snow

#
Thanks for including an example that could be copied and pasted.
However TkPredict and Predict.Plot both need at least one numeric (not
factor) predictor.  So I added another column called x that was just
1:5 to the sample data frame and included it in the model.

Here are a couple of approaches using for loops:

tmp.df <- expand.grid( home=c('own','rent'), income=c('20','50'),
	gender=c('F','M') )

par(ask=TRUE)
for( i in seq_len(nrow(tmp.df)) ) {
	Predict.Plot(m1, 'x', home=tmp.df$home[i], income=tmp.df$income[i],
		gender=tmp.df$gender[i])
	title( sprintf( "Home %s, Income %s, Gender %s", tmp.df$home[i],
		tmp.df$income[i], tmp.df$gender[i] ))
}
par(ask=FALSE)


Predict.Plot(m1, 'x', home='own', income='20', gender='F', x=-1:5)
for(i in 2:nrow(tmp.df) ) {
	Predict.Plot(m1, 'x', home=tmp.df$home[i], income=tmp.df$income[i],
		gender=tmp.df$gender[i], add=TRUE, plot.args=list(col=i))
}
legend( 'topleft', with(tmp.df, paste(home,income,gender)),
	lty=1, col=1:8)


For the first example, if you want to save the individual plots you
should either open a pdf device, then run the loop.  Or, include a
command in the loop to save the plot.

Hope this helps,
On Tue, Sep 11, 2012 at 5:16 PM, Abraham Mathew <abmathewks at gmail.com> wrote: