[R] How to plot predicted probabilities with 95% CIs

Faradj Koliev faradj.g at gmail.com
Mon Oct 3 09:15:39 CEST 2016


Dear all, 

I need a little help with plotting predicted probabilities (values). Consider the following example

**
data(”mtcars”) 

mfit = lm(mpg ~ vs + disp + cyl, data=mtcars)

newcar=data.frame(vs=c(0,1), disp=230, cyl=6.188)

Pmodel<–predict(mfit, newcar) 
**

I want to plot the effect of ”vs” ( 0 and 1) when all other variables are held constant (mean).  

To do this I run this code below:
**
plot(1:2, Pmodel$estimates[1:2,1],ylim=c(0,1),pch=19, xlim=c(.5,2.5), xlab=”X", ylab=”Predicted value of Y", xaxt="n", main= ”Predicted value of Y with 95% CIs")
arrows(1:2, (Pmodel $estimates[1:2,1]-1.96*Pmodel$estimates[1:2,2]), 1:2, (Pmodel$estimates[1:2,1]+1.96*Pmodel$estimates[1:2,2]), length=0.05, angle=90, code=3)
axis(1,at=c(1,2), labels=c(”Yes”,"No"))
**
What am I doing wring here? Thanks! 

Best, 
Faradj 
	[[alternative HTML version deleted]]



More information about the R-help mailing list