Skip to contents

Generate a new, resampled dataset of the same shape as data following the given model. The covariates are kept the same and the response variables are drawn according to model$sample_yx().

Usage

resample_param(data, model)

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.0277     0  0.319
#>  2 0.980      1  4.73 
#>  3 0.244      0  0.293
#>  4 0.720      1  5.06 
#>  5 0.621      0  1.20 
#>  6 0.236      1  5.09 
#>  7 0.0347     0 -0.590
#>  8 0.624      1  3.80 
#>  9 0.275      0  0.501
#> 10 0.566      0 -0.867