At least in simple cases, the output of the variance function should be of length the number of columns of the Y variable in input.
MWE (thanks to @ThomasDeroyon) :
data <- data.frame(id = 1:100, sex= c(rep(1, 50), rep(2, 50)),
y = c(rnorm(50, 1, 3), rnorm(50, 2, 4)), weight = rep(10, 100))
# Dont't work
variance_function <- function(y) 1
variance_wrapper <- gustave::define_variance_wrapper(variance_function = variance_function,
reference_id = data$id,
reference_weight = data$weight,
default_id = "id")
variance_wrapper(data, as.factor(sex))
# Works
variance_function <- function(y) rep(1, NCOL(y))
variance_wrapper <- gustave::define_variance_wrapper(variance_function = variance_function,
reference_id = data$id,
reference_weight = data$weight,
default_id = "id")
variance_wrapper(data, as.factor(sex))
At least in simple cases, the output of the variance function should be of length the number of columns of the Y variable in input.
MWE (thanks to @ThomasDeroyon) :