Last active
December 7, 2018 16:09
-
-
Save Stan125/33b2ba2610d6b893311943b0f42a6e80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script shows an error in my package distreg.vis | |
library(distreg.vis) | |
library(bamlss) | |
fam_name <- "gamma" | |
art_data <- model_fam_data(fam_name = fam_name) | |
fam_called <- do.call(get(paste0(fam_name, "_bamlss"), | |
envir = as.environment("package:bamlss")), | |
args = list()) | |
# Different formulas depending on number of parameters | |
form_list <- list(as.formula(paste0(fam_name, "~ norm2 + binomial1"))) | |
if (length(fam_called$names) > 1) | |
form_list[[2]] <- ~ norm2 + binomial1 | |
# New data | |
ndata <- art_data[sample(seq_len(nrow(art_data)), 1), | |
!colnames(art_data) %in% fam_name] | |
# Create model | |
model <- bamlss(form_list, data = art_data, family = fam_called, | |
verbose = FALSE) | |
# Predicted moments | |
pred_params <- preds(model, newdata = ndata) | |
moms <- distreg.vis::moments(pred_params, fam_name) | |
# Sample-based predicted moments | |
samps <- predict(model, newdata = ndata, FUN = function(x) return(x)) | |
samps <- as.data.frame(lapply(samps, t)) | |
samp_moms <- moments(par = samps, fam_name = fam_name) | |
apply(samp_moms, 2, mean);moms | |
#> Expected_Value Variance | |
#> 1.3121486 0.7620629 | |
#> Expected_Value Variance | |
#> 325 3.714977 1.428629 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment