Graphics Reference
In-Depth Information
lm_predicted
<-
predictvals(modlinear,
"ageYear"
,
"heightIn"
)
loess_predicted
<-
predictvals(modloess,
"ageYear"
,
"heightIn"
)
sp
+
geom_line(data
=
lm_predicted, colour
=
"red"
, size
=
.8
)
+
geom_line(data
=
loess_predicted, colour
=
"blue"
, size
=
.8
)
Figure 5-22. Left: a quadratic prediction line from an lm object; right: prediction lines from linear
(red) and LOESS (blue) models
For
glm
models that use a nonlinear link function, you need to specify
type="response"
to the
predictvals()
function. This is because the default behavior is to return predicted values in
the scale of the linear predictors, instead of in the scale of the response (y) variable.
0 to 1, while
class
is a factor, we'll first have to convert
class
to 0s and 1s:
library(MASS)
# For the data set
b
<-
biopsy
b$classn[b$class
==
"benign"
]
<-
0
b$classn[b$class
==
"malignant"
]
<-
1
Next, we'll perform the logistic regression:
fitlogistic
<-
glm(classn ~ V1, b, family
=
binomial)