# [R] How to draw a graph after model selection?

Greg Snow 538280 at gmail.com
Wed Oct 3 19:47:09 CEST 2012

```Fit the model in R rather than trying to bring the coefficients in
from another program.  Then you can use the predict function to get
the predictions from that model to plot.  Or even easier, use the
Predict.Plot or TkPredict functions from the TeachingDemos package
with the fitted model object.

On Wed, Oct 3, 2012 at 8:21 AM, ahbu <deliaquek1 at yahoo.com.sg> wrote:
> I am very new to R and I basically used SPSS to do my model selection, which
> I had used generalized linear model.
>
> So my best model is P= D + T + L + T*L and there is a parameters table from
> the SPSS output which I suppose I have to use the coefficients (column B) in
> the table (as attached) when I draw my graph in R.
>
> I want to draw a graph in R which x-axis is D, using the model and the
> relevant coefficients. From what I read online, this is the code I've got
> but I am not sure if it is correct as I keep getting "In Ops.factor((0.195),
> dataT1\$T) : * not meaningful for factors" when I tried to sub in values."
>
> plot(dataT1\$D, dataT1\$P, ylab = "Percentage carrion weight left", xlab =
> "Day")
> *T1 <- (0.205)*dataT1\$D + (0.195)*dataT1\$T + 0.227*       #DO I SUB IN MY
> EQUATION HERE?#
> p.average1 <- exp(T1) / (1 + exp(T1))
> I1 <- order(dataT1\$D)
> lines(dataT1\$D[I1],p.average1[I1],lwd=2, col="red")
> p.Upp1 <- exp(T1 + 1.96*0.19215)/(1+exp(T1 + 1.96*0.19215))
> p.Low1 <- exp(T1 - 1.96*0.19215)/(1+exp(T1 - 1.96*0.19215))
> lines(dataT1\$D[I1], p.Upp1[I1], col="red")
> lines(dataT1\$D[I1], p.Low1[I1], col="red")
>
> I am supposed to draw a graph where I fix D and T and draw P against D. How
> am I supposed to do that???
>
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-draw-a-graph-after-model-selection-tp4644876.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help