Parametric resampling scheme for a parametric regression model with resampling of covariates
Source:R/ResamplingSchemes.R
resample_param_rsmplx.Rd
Generate a new, resampled dataset of the same shape as data
following the given model. The covariates are resampled from data$x
and
the response variables are drawn according to model$sample_yx()
.
Arguments
- data
data.frame()
with columns x and y containing the original data- model
ParamRegrModel to use for the resampling
Value
data.frame()
with columns x and y containing the resampled data
Examples
# Create an example dataset
n <- 10
x <- cbind(runif(n), rbinom(n, 1, 0.5))
model <- NormalGLM$new()
params <- list(beta = c(2, 3), sd = 1)
y <- model$sample_yx(x, params = params)
data <- dplyr::tibble(x = x, y = y)
# Fit the model to the data
model$fit(data, params_init = params, inplace = TRUE)
# Resample from the model given data
resample_param(data, model)
#> # A tibble: 10 × 2
#> x[,1] [,2] y
#> <dbl> <dbl> <dbl>
#> 1 0.554 1 4.16
#> 2 0.303 0 0.321
#> 3 0.446 0 0.0683
#> 4 0.315 1 3.52
#> 5 0.142 1 3.33
#> 6 0.491 1 4.27
#> 7 0.650 1 5.11
#> 8 0.407 1 3.99
#> 9 0.755 0 0.645
#> 10 0.483 0 -0.836