Why not use the effects package -- designed for this task.

library(effects)
plot(allEffects(mfit))

?plot.eff   # for details

On 10/3/2016 3:15 AM, Faradj Koliev wrote:
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]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to