plotPredy.RdPlots the best fit line for a model with one y variable and one x variable, or with one y variable and polynomial x variables.
plotPredy(
data,
x,
y,
model,
order = 1,
x2 = NULL,
x3 = NULL,
x4 = NULL,
x5 = NULL,
pch = 16,
xlab = "X",
ylab = "Y",
length = 1000,
lty = 1,
lwd = 2,
col = "blue",
type = NULL,
...
)The name of the data frame.
The name of the x variable.
The name of the y variable.
The name of the model object.
If plotting a polynomial function, the order of the polynomial.
Otherwise can be left as 1.
If applicable, the name of the second order polynomial x variable.
If applicable, the name of the third order polynomial x variable.
If applicable, the name of the fourth order polynomial x variable.
If applicable, the name of the fifth order polynomial x variable.
The shape of the plotted data points.
The label for the x-axis.
The label for the y-axis.
The number of points used to draw the line.
The style of the plotted line.
The width of the plotted line.
The col of the plotted line.
Passed to predict. Required for certain models.
Other arguments passed to plot.
Produces a plot. Returns nothing.
Any model for which predict() is defined can be used.
### Plot of linear model fit with lm
data(BrendonSmall)
model = lm(Weight ~ Calories, data = BrendonSmall)
plotPredy(data = BrendonSmall,
y = Weight,
x = Calories,
model = model,
xlab = "Calories per day",
ylab = "Weight in kilograms")
### Plot of polynomial model fit with lm
data(BrendonSmall)
BrendonSmall$Calories2 = BrendonSmall$Calories * BrendonSmall$Calories
model = lm(Sodium ~ Calories + Calories2, data = BrendonSmall)
plotPredy(data = BrendonSmall,
y = Sodium,
x = Calories,
x2 = Calories2,
model = model,
order = 2,
xlab = "Calories per day",
ylab = "Sodium intake per day")
### Plot of quadratic plateau model fit with nls
data(BrendonSmall)
quadplat = function(x, a, b, clx) {
ifelse(x < clx, a + b * x + (-0.5*b/clx) * x * x,
a + b * clx + (-0.5*b/clx) * clx * clx)}
model = nls(Sodium ~ quadplat(Calories, a, b, clx),
data = BrendonSmall,
start = list(a = 519,
b = 0.359,
clx = 2304))
plotPredy(data = BrendonSmall,
y = Sodium,
x = Calories,
model = model,
xlab = "Calories per day",
ylab = "Sodium intake per day")
### Logistic regression example requires type option
data(BullyHill)
Trials = cbind(BullyHill$Pass, BullyHill$Fail)
model.log = glm(Trials ~ Grade, data = BullyHill,
family = binomial(link="logit"))
plotPredy(data = BullyHill,
y = Percent,
x = Grade,
model = model.log,
type = "response",
xlab = "Grade",
ylab = "Proportion passing")