# NOT RUN {
# Compile some test data
data('ChickWeight')
set.seed(10)
tr <- sample(c(TRUE, FALSE), nrow(ChickWeight), TRUE, c(0.7, 0.3))
y_tr <- ChickWeight$weight[tr]
y_te <- ChickWeight$weight[!tr]
x_tr <- apply(ChickWeight[tr, -1], 2, as.numeric)
x_te <- apply(ChickWeight[!tr, -1], 2, as.numeric)
var_type_x <- apply(x_tr, 2,
function(x) if(length(unique(x)) < 10) "d" else "c")
# Fit model to training data
md <- copulareg::copulareg(y_tr, x_tr, "c", var_type_x)
# Predict for a new data matrix
pred <- predict(md, new_x = x_te)
# Plot residuals for test data against covariates
plot(data.frame(residual = y_te - pred, x_te))
# Plot residuals against fitted
plot(md)
# Plot prediction error against predicted values
plot(md, new_x=x_te, new_y=y_te)
# }
Run the code above in your browser using DataLab