Description Usage Arguments Value Examples
Predictive Plot for Model
1 |
x |
- vector containing spline terms |
fHat |
- vector of prediction values |
lb |
- vector containing lower bound of confidence interval |
ub |
-vector containing upper bound of confidence interval |
title |
- optional string for title of the plot |
x_lab |
- string for title of x axis |
y_lab |
- string for title of y axis |
pred_type |
- string indicating "link" or "response" |
None
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # Load required packaged
library(mgcv); library(HRW)
# Load the data
data(BostonMortgages)
#Create model for data
fit = gam(deny ~ black + s(dir), family = binomial, data = BostonMortgages)
#Create data frame for prediction
ng = 1001
dir_seq = seq(min(BostonMortgages$dir), max(BostonMortgages$dir), length = ng)
black = BostonMortgages$black
black_seq = rep(unique(black)[which.max(tabulate(match(black, unique(black))))], ng)
#Get predicted y values, lower bound, and upper bound of confidence interval
newdata = data.frame(dir = dir_seq, black =black_seq)
pred_fit = predict(fit, newdata, se.fit = TRUE)
fHat = pred_fit$fit
lb = fHat - qnorm(0.975) * pred_fit$se.fit
ub = fHat + qnorm(0.975) * pred_fit$se.fit
#Plot the predictive plot
.get_plot(dir_seq, fHat, lb, ub, x_lab = "dir", y_lab = "deny", pred_type = "link")
.get_plot(dir_seq, fHat, lb, ub, x_lab = "dir", y_lab = "deny", pred_type = "response")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.