Provides utilities for preparing, validating, summarising, and
documenting survey data from primary and auxiliary samples, and for
specifying and checking survey-design information. The package supports
data-management and design-specification steps in two-sample calibrated
imputation workflows. For background on survey calibration, see Deville
and Särndal (1992)
TwoSampleCalImpute provides computational tools for preparing, validating, cleaning, and exporting survey data when auxiliary information is available from a separate reference sample.
The package currently provides functions for standardized data import, basic data-integrity validation, controlled data cleaning, and CSV export. These utilities support data preparation for Two-Sample Calibrated Imputation workflows.
You can install the development version from GitHub using the remotes package:
install.packages("remotes")
remotes::install_github("Kamun2026/TwoSampleCalImpute")
After installation, load the package with:
library(TwoSampleCalImpute)
Create a small example of primary-sample data and import it:
primary_data <- data.frame(
id = 1:5,
age = c(25, 32, 41, 29, 36),
outcome = c(1, 0, 1, 1, 0)
)
primary <- tsci_import_data(
primary_data,
sample_type = "primary",
id = "id"
)
print(primary)
Check data integrity, missing values, and duplicate record identifiers:
validation <- tsci_validate_data(
primary_data,
data_name = "primary sample",
key = "id"
)
validation$valid
For the example above, validation returns TRUE.
Import the data and remove completely empty rows and columns when requested:
cleaned <- tsci_clean_data(
tsci_import_data(primary_data, sample_type = "primary", id = "id"),
remove_empty_rows = TRUE,
remove_empty_columns = TRUE
)
print(cleaned)
Export the cleaned data to a CSV file:
export_file <- file.path(tempdir(), "example_export.csv")
tsci_export_data(cleaned, file = export_file)
file.exists(export_file)
The export path can be changed to a suitable location when working with real survey data.