lebebr01/simglm

how to add factor covariates in a single level Logistic Regression model

aipie0066 opened this issue · 1 comments

Thanks for the great job.
A question I had is, how to add factor covariates in a single level Logistic Regression model.
I tried the below code but get an error.
fixed<- ~ 1 + + act + diff + numCourse_f
fixed_param <- c(2, 2, 1, 0.5)
cov_param <- list(dist_fun = c('rnorm', 'rnorm'),
var_type = c("single", "single"),
opts = list(list(mean = 0, sd = 4),
list(mean = 0, sd = 3)))
fact_vars <- list(numlevels = 2, replace = TRUE, prob = NULL, var_type = "single")
n <- 1500
temp_single <- sim_glm(fixed = fixed, fixed_param = fixed_param,
cov_param = cov_param, fact_vars = fact_vars,
n = n, data_str = "single", outcome_type = 'logistic')
Error in dimnames(x) <- dn :
length of 'dimnames' [2] not equal to array extent

what am I missing?

This is a bug in the currently released CRAN version. A major update will be coming soon that will fix this and will introduce a new syntax style that is hopefully more flexible modeled after tidy data tools.

Below is an example of this new format:

devtools::install_github('lebebr01/simglm@tidy_sim')

sim_arguments <- list(
  formula = resp_var ~ 1 + act + diff + factor(num_course),
  reg_weights = c(2, 2, 1, 0.5),
  fixed = list(
    act = list(var_type = 'continuous', mean = 0, sd = 4),
    diff = list(var_type = 'continuous', mean = 0, sd = 3),
    num_course = list(var_type = 'factor', levels = 2)
  ),
  outcome_type = 'logistic',
  sample_size = 1500
)

sim_arguments %>%
  simulate_fixed(data = NULL, .) %>%
  generate_response(sim_arguments)