Description Usage Arguments Details Value Examples
cv_abm
uses cross-validation to test an ABM's predictive power.
1 2 3 4 5 6 7 8 9 | cv_abm(data, features, Formula, agg_patterns, abm_simulate, abm_vars, iters,
tseries_len, tp = rep(tseries_len, nrow(agg_patterns)),
package = c("caretglm", "caretglmnet", "glm", "caretnnet", "caretdnn"),
sampling = FALSE, sampling_size = 1000, STAT = c("mean", "median"),
saving = FALSE, filename = NULL, abm_optim = c("GA", "DE"),
validate = c("lgocv", "cv"), folds = ifelse(validate == "lgocv",
max(data$group), 10), drop_nzv = FALSE, verbose = TRUE,
predict_test_par = FALSE, optimize_abm_par = FALSE,
parallel_training = FALSE)
|
data |
|
features |
|
Formula |
|
agg_patterns |
data.frame with rows (observational unit) being the group
and columns: (a.) those aggregate level variables needed for the prediction
with the specified |
abm_simulate |
function with these arguments: |
abm_vars |
a list with either (1.) a numeric vector named "lower" AND a
numeric vector named "upper" each the length of the number of tuning_params
of ABM (the names of the elements of these vecs should be the names of the
variables and they should be in the same order that the |
iters |
numeric vector length one specifying number of iterations to simulate ABM for. |
tseries_len |
numeric vector length one specifying maximum number of time
periods to use for model training and testing. If some groups have less than
the maximum then you need to provide a vector to the |
tp |
optional numeric vector length number of rows of |
package |
optional character vector length one, default is
|
sampling |
optional logical vector length one, default is |
sampling_size |
optional numeric vector length one specifying how many
observations from each group that |
STAT |
optional character vector length one, default is |
saving |
optional logical vector length one, default is |
filename |
optional character vector length one, default is |
abm_optim |
optional character vector length one, default is
|
validate |
optional character vector length one, default is
|
folds |
optional numeric vector length one, default is
|
drop_nzv |
optional logical vector length one, default is |
verbose |
optional logical vector length one, default is |
predict_test_par |
optional logical vector length one, default is
|
optimize_abm_par |
optional logical vector length one, default is
|
parallel_training |
optional logical vector length one, default is
|
The function returns an S4 object. See cv_abm for the details of
the slots
(objects) that this type of object will have.
Returns an S4 object of class cv_abm. With slots for
call = "language", predicted_patterns = "list", timing = "numeric",
and diagnostics = "character"
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # Create data:
cdata <- data.frame(period = rep(seq(10), 1000),
action = rep(0:1, 5000),
my.decision1 = sample(1:0, 10000, TRUE),
other.decision1 = sample(1:0, 10000, TRUE),
group = c(rep(1, 5000), rep(2, 5000)))
time_len <- 2
agg_patterns <- data.frame(group = c(1,2),
action = c( mean(as.numeric(cdata[cdata$group==1, "action"])),
mean(as.numeric(cdata[cdata$group==2, "action"]))),
c(eat::period_vec_create(cdata[cdata$group==1, ], time_len)[1],
eat::period_vec_create(cdata[cdata$group==2, ], time_len)[1]),
c(eat::period_vec_create(cdata[cdata$group==1, ], time_len)[2],
eat::period_vec_create(cdata[cdata$group==2, ], time_len)[2]))
names(agg_patterns)[3:4] <- c("1", "2")
# Create ABM:
simulate_abm <- function(model, features, parameters, time_len,
tuning_parameters,
iterations = 1250, STAT = "mean"){
matrixOut <- data.frame(period = rep(1:10, 1000),
action = rep(0:1, 5000),
my.decision1 = sample(1:0, 10000, TRUE),
other.decision1 = sample(1:0, 10000, TRUE))
action_avg <- mean(matrixOut$action, na.rm=TRUE)
dynamics <- period_vec_create(matrixOut, time_len)
list(dynamics = dynamics, action_avg = action_avg, simdata = matrixOut)
}
# Create features and formula lists:
k <- 1
features <- as.list(rep(NA, k)) # create list to fill
features[[1]] <- c("my.decision1", "other.decision1")
Formula <- as.list(rep(NA, k)) # create list to fill
Formula[[1]] <- "action ~ my.decision1 + other.decision1"
# Call cv_abm():
res <- cv_abm(cdata, features, Formula, agg_patterns,
abm_simulate = simulate_abm,
abm_vars = list(values = c(0.3, 0.5)),
iters = 1000,
tseries_len = time_len,
tp = c(1, 2),
package = "caretglm",
STAT = "mean",
saving = FALSE, filename = NULL,
validate = "lgocv",
drop_nzv = FALSE,
predict_test_par = FALSE)
summary(res)
#plot(res)
#performance(res, "cor_pval")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.