Description Usage Arguments Details Value Note Author(s) See Also Examples

These functions create a plot of predicted values vs. one of the predictors for given values of the other predictors. TkPredict further creates a Tk gui to allow you to change the values of the other predictors.

1 2 3 4 |

`model` |
A model of class 'lm' or 'glm' (or possibly others) from which to plot predictions. |

`pred.var` |
A character string indicating which predictor variable to put on the x-axis of the plot. |

`...` |
for |

`type` |
The type value passed on to the predict function. |

`add` |
Whether to add a line to the existing plot or start a new plot. |

`plot.args` |
A list of additional options passed on to the plotting function. |

`n.points` |
The number of points to use in the approximation of the curve. |

`ref.val` |
A reference value for the |

`ref.col, ref.lty` |
The color and line type of the reference line if plotted. |

`data` |
The data frame or environment where the variables that the model was fit to are found. If missing, the model will be examined for an attempt find the needed data. |

These functions plot the predicted values from a regression model
(`lm`

or `glm`

) against one of the predictor variables for
given values of the other predictors. The values of the other
predictors are passed as the `...`

argument to
`Predict.Plot`

or are set using gui controls in `TkPredict`

(initial values are the medians).

If the variable for the x axis (name put in `pred.var`

) is not
included with the `...`

variables, then the range will be
computed from the `data`

argument or the data component of the
`model`

argument.

If the variable passed as `pred.var`

is also included in the
`...`

arguments and contains a single value, then this value will
be used as the `ref.val`

argument.

If it contains 2 or more values, then the range of these values will be used as the x-limits for the predictions.

When running `TkPredict`

you can click on the "Print Call" button
to print out the call of `Predict.Plot`

that will recreate the
same plot. Doing this for different combinations of predictor values
and editing the `plot.args`

and `add`

arguments will give
you a script that will create a static version of the predictions.

These functions are run for their side effects of creating plots and do not return anything.

The GUI currently allows you to select a factor as the x-variable. If you do this it will generate some errors and you will not see the plot, just choose a different variable as the x-variable and the plot will return.

Greg Snow, [email protected]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ```
library(splines)
fit.lm1 <- lm( Sepal.Width ~ ns(Petal.Width,3)*ns(Petal.Length,3)+Species,
data=iris)
Predict.Plot(fit.lm1, pred.var = "Petal.Width", Petal.Width = 1.22,
Petal.Length = 4.3, Species = "versicolor",
plot.args = list(ylim=range(iris$Sepal.Width), col='blue'),
type = "response")
Predict.Plot(fit.lm1, pred.var = "Petal.Width", Petal.Width = 1.22,
Petal.Length = 4.3, Species = "virginica",
plot.args = list(col='red'),
type = "response", add=TRUE)
Predict.Plot(fit.lm1, pred.var = "Petal.Width", Petal.Width = 1.22,
Petal.Length = 4.4, Species = "virginica",
plot.args = list(col='purple'),
type = "response", add=TRUE)
fit.glm1 <- glm( Species=='virginica' ~ Sepal.Width+Sepal.Length,
data=iris, family=binomial)
Predict.Plot(fit.glm1, pred.var = "Sepal.Length", Sepal.Width = 1.99,
Sepal.Length = 6.34, plot.args = list(ylim=c(0,1), col='blue'),
type = "response")
Predict.Plot(fit.glm1, pred.var = "Sepal.Length", Sepal.Width = 4.39,
Sepal.Length = 6.34, plot.args = list(col='red'),
type = "response", add=TRUE)
if(interactive()){
TkPredict(fit.lm1)
TkPredict(fit.glm1)
}
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.