Nothing
knitr::opts_chunk$set(collapse = TRUE, comment = "#>") library(rMIDAS2) can_mock <- requireNamespace("jsonlite", quietly = TRUE)
rMIDAS2 is a lightweight R client for the MIDAS2 Python package.
It lets you perform multiple imputation using denoising autoencoders
without using reticulate at runtime.
The chunk below runs during vignette build. It uses mocked HTTP responses, so it exercises the package interface without requiring a live Python backend.
mock_json_response <- function(body, status = 200L) { function(req) { httr2::response( status_code = status, headers = list("Content-Type" = "application/json"), body = charToRaw(jsonlite::toJSON(body, auto_unbox = TRUE)) ) } } pkg_env <- rMIDAS2:::.pkg_env old_process <- pkg_env$process old_port <- pkg_env$port old_base_url <- pkg_env$base_url on.exit({ pkg_env$process <- old_process pkg_env$port <- old_port pkg_env$base_url <- old_base_url }, add = TRUE) pkg_env$process <- list(is_alive = function() TRUE) pkg_env$port <- 9999L pkg_env$base_url <- "http://127.0.0.1:9999" example_data <- data.frame( Y = c(1.2, -0.4, 0.7), X1 = c(NA, 0.5, -1.1), X2 = c(0.3, 1.4, -0.2) ) mock_complete <- mock_json_response(list( model_id = "mod-001", m = 2, columns = list("Y", "X1", "X2"), imputations = list( list(list(1.2, 0.1, 0.3), list(-0.4, 0.5, 1.4), list(0.7, -1.1, -0.2)), list(list(1.2, 0.2, 0.3), list(-0.4, 0.5, 1.4), list(0.7, -1.1, -0.2)) ) )) result <- httr2::with_mocked_responses(mock_complete, { midas(example_data, m = 2, epochs = 1) }) result$model_id head(result$imputations[[1]])
install_backend(method = "pip")
set.seed(42) n <- 500 df <- data.frame( Y = rnorm(n), X1 = rnorm(n), X2 = rnorm(n) ) df$X1[df$X2 > 0.5] <- NA head(df)
result <- midas(df, m = 10, epochs = 20) # View first imputed dataset head(result$imputations[[1]])
# Fit the model fit <- midas_fit(df, epochs = 20) # Generate imputations — pass the fitted object directly imps <- midas_transform(fit, m = 10) head(imps[[1]])
mean_df <- imp_mean(fit) head(mean_df)
reg <- combine(fit, y = "Y") reg
diag <- overimpute(fit, mask_frac = 0.1) diag$mean_rmse diag$rmse
stop_server()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.