| Title: | Inference for Released Plug-in Sampling Synthetic Dataset |
|---|---|
| Description: | Considering the singly imputed synthetic data generated via plug-in sampling under the multivariate normal model, draws inference procedures including the generalized variance, the sphericity test, the test for independence between two subsets of variables, and the test for the regression of one set of variables on the other. For more details see Klein et al. (2021) <doi:10.1007/s13571-019-00215-9>. |
| Authors: | Vítor Augusto [aut] (ORCID: <https://orcid.org/0009-0004-9003-3558>), Mina Norouzirad [aut] (ORCID: <https://orcid.org/0000-0003-0311-6888>), Miguel Fonseca [ctb] (ORCID: <https://orcid.org/0000-0002-0162-8372>), Ricardo Moura [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-3003-9235>), FCT, I.P. [fnd] (under the scope of the projects UID/00297/2025 and UID/PRR/00297/2025 (NovaMath)) |
| Maintainer: | Ricardo Moura <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-07-13 18:26:59 UTC |
| Source: | https://github.com/ricardomourarpm/psinference |
Standardized physicochemical measurements from 37 cultivated fields on
loess-silt parent material in Brittany, France, derived from Morvan
et al. (2023). The dataset provides a realistic statistical disclosure
control (SDC) example with variables arranged in two natural
blocks of size .
The first block contains standard agronomic indicators that are treated as public variables. The second block contains farm-management indicators that are treated as sensitive variables and are therefore suitable for illustrating plug-in sampling (PS) synthetic data releases.
brittany_soil_psbrittany_soil_ps
A numeric matrix with 37 rows and 6 columns. All variables are standardized to mean zero and standard deviation one:
Soil pH measured in water suspension.
Soil pH measured in 1 M KCl suspension.
Log cation exchange capacity, Metson method (log meq per 100 g soil).
Log soil organic carbon (log g/kg).
Log total soil nitrogen (log g/kg).
Log Olsen-P available phosphorus (log g P2O5/kg).
The full dataset from Morvan et al. (2023) contains 137 fields across three parent-material types. This version retains only the most frequent parent-material group, loess-silt.
Variables with approximately log-normal distributions, namely
cation exchange capacity, organic carbon, total nitrogen, and Olsen-P,
were log-transformed. Mahalanobis outliers were removed using the
cutoff. The retained variables were then
standardized.
For illustrative SDC purposes, the variables are partitioned into two blocks:
pH_water, pH_KCl, and log_CEC_Metson.
log_Organic_C, log_Total_N, and log_P_Olsen.
This block structure is useful for illustrating independence, regression, and covariance-based inference when one block is released as observed data and the other block is released through PS synthetic draws.
Normality was assessed using the diagnostics implemented in
mvn_test. None of the retained diagnostics rejected
multivariate normality at the 5% level.
Morvan, T., Lambert, Y., Germain, P., Lemercier, B., Moreira, M., and Beff, L. (2023). A dataset of physico-chemical properties, extractable organic N, N mineralisation and physical organic matter fractionation of soils. Data in Brief, 51, 109776. doi:10.1016/j.dib.2023.109776
Data repository, licensed under CC BY 4.0: doi:10.57745/DGIPGR
mvn_test,
simSynthData,
ps_test,
independence_test,
regression_test
data(brittany_soil_ps) dim(brittany_soil_ps) colnames(brittany_soil_ps) # Public and sensitive blocks public_block <- c("pH_water", "pH_KCl", "log_CEC_Metson") sensitive_block <- c("log_Organic_C", "log_Total_N", "log_P_Olsen") # Check multivariate normality mvn_test(brittany_soil_ps, hz_nsim = 500, plot = FALSE) # Generate three PS synthetic releases set.seed(1) V3 <- simSynthData(brittany_soil_ps, M = 3) # Test independence between the public and sensitive blocks independence_test( V3, M = 3, group_a = public_block, group_b = sensitive_block, iterations = 500L )data(brittany_soil_ps) dim(brittany_soil_ps) colnames(brittany_soil_ps) # Public and sensitive blocks public_block <- c("pH_water", "pH_KCl", "log_CEC_Metson") sensitive_block <- c("log_Organic_C", "log_Total_N", "log_P_Olsen") # Check multivariate normality mvn_test(brittany_soil_ps, hz_nsim = 500, plot = FALSE) # Generate three PS synthetic releases set.seed(1) V3 <- simSynthData(brittany_soil_ps, M = 3) # Test independence between the public and sensitive blocks independence_test( V3, M = 3, group_a = public_block, group_b = sensitive_block, iterations = 500L )
Simulates the null distribution of the regression pivotal statistic
under plug-in sampling for releases.
The simulation uses the same compound Wishart structure as
Inddist:
canodist(part, nsample, pvariates, iterations = 10000L, M = 1L)canodist(part, nsample, pvariates, iterations = 10000L, M = 1L)
part |
Size of the first variable block, |
nsample |
Original sample size |
pvariates |
Total number of variables, |
iterations |
Number of Monte Carlo draws. The default is
|
M |
Number of synthetic releases. The default is |
A numeric vector of length iterations.
set.seed(1) nd1 <- canodist( part = 2, nsample = 50, pvariates = 4, M = 1, iterations = 1000L ) stats::quantile(nd1, probs = 0.95) nd5 <- canodist( part = 2, nsample = 50, pvariates = 4, M = 5, iterations = 1000L ) stats::quantile(nd5, probs = 0.95) canodist(part = 2, nsample = 50, pvariates = 4, M = 5) |> quantile(0.95)set.seed(1) nd1 <- canodist( part = 2, nsample = 50, pvariates = 4, M = 1, iterations = 1000L ) stats::quantile(nd1, probs = 0.95) nd5 <- canodist( part = 2, nsample = 50, pvariates = 4, M = 5, iterations = 1000L ) stats::quantile(nd5, probs = 0.95) canodist(part = 2, nsample = 50, pvariates = 4, M = 5) |> quantile(0.95)
Backward-compatible alias for gv_test.
gv_ci(V, M = 1L, Sigma, alpha = 0.05, iterations = 10000L, null_dist = NULL)gv_ci(V, M = 1L, Sigma, alpha = 0.05, iterations = 10000L, null_dist = NULL)
V |
Stacked synthetic data set, given as an |
M |
Positive integer giving the number of synthetic releases.
The default is |
Sigma |
A |
alpha |
Significance level. The default is |
iterations |
Monte Carlo sample size used to approximate the
null distribution. The default is |
null_dist |
Optional numeric vector containing a precomputed null
distribution. If supplied, |
Tests and computes a
-level confidence interval for the generalized
variance , based on released plug-in sampling
synthetic data sets stacked into V. Setting M = 1
recovers the single-release procedure of Klein et al. (2021).
gv_test(V, M = 1L, Sigma, alpha = 0.05, iterations = 10000L, null_dist = NULL)gv_test(V, M = 1L, Sigma, alpha = 0.05, iterations = 10000L, null_dist = NULL)
V |
Stacked synthetic data set, given as an |
M |
Positive integer giving the number of synthetic releases.
The default is |
Sigma |
A |
alpha |
Significance level. The default is |
iterations |
Monte Carlo sample size used to approximate the
null distribution. The default is |
null_dist |
Optional numeric vector containing a precomputed null
distribution. If supplied, |
An object of class ps_test with component
conf.int giving the exact confidence interval for
. The usual S3 methods, including print,
summary, and plot, are available.
Klein, M., Moura, R., and Sinha, B. (2021). Multivariate normal inference based on singly imputed synthetic data under plug-in sampling. Sankhya B, 83, 273–287. doi:10.1007/s13571-019-00215-9
data(brittany_soil_ps) set.seed(1) V1 <- simSynthData(brittany_soil_ps) res <- gv_test(V1, M = 1, Sigma = cov(brittany_soil_ps), iterations = 1000L ) print(res) plot(res) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) res5 <- gv_test(V5, M = 5, Sigma = cov(brittany_soil_ps), iterations = 1000L ) print(res5) plot(res5)data(brittany_soil_ps) set.seed(1) V1 <- simSynthData(brittany_soil_ps) res <- gv_test(V1, M = 1, Sigma = cov(brittany_soil_ps), iterations = 1000L ) print(res) plot(res) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) res5 <- gv_test(V5, M = 5, Sigma = cov(brittany_soil_ps), iterations = 1000L ) print(res5) plot(res5)
Simulates the null distribution of the generalized variance pivotal
statistic under plug-in sampling.
Under the multiple-release stacking result,
the Bartlett decomposition gives
where comes from the synthetic Wishart
distribution with degrees of freedom , and
comes from the original-sample Wishart
distribution with degrees of freedom . All
variables are mutually independent.
For , and have the same
distribution, recovering the single-release result
of Klein et al. (2021).
GVdist(nsample, pvariates, iterations = 10000L, M = 1L)GVdist(nsample, pvariates, iterations = 10000L, M = 1L)
nsample |
Original sample size |
pvariates |
Number of variables |
iterations |
Number of Monte Carlo draws. The default is
|
M |
Number of synthetic releases. The default is |
A numeric vector of length iterations containing draws from the
null distribution of .
Klein, M., Moura, R., and Sinha, B. (2021). Multivariate normal inference based on singly imputed synthetic data under plug-in sampling. Sankhya B, 83, 273–287. doi:10.1007/s13571-019-00215-9
set.seed(1) # Single release nd1 <- GVdist(nsample = 50, pvariates = 4, M = 1, iterations = 1000L) stats::quantile(nd1, probs = c(0.025, 0.975)) # Five releases nd5 <- GVdist(nsample = 50, pvariates = 4, M = 5, iterations = 1000L) stats::quantile(nd5, probs = c(0.025, 0.975))set.seed(1) # Single release nd1 <- GVdist(nsample = 50, pvariates = 4, M = 1, iterations = 1000L) stats::quantile(nd1, probs = c(0.025, 0.975)) # Five releases nd5 <- GVdist(nsample = 50, pvariates = 4, M = 5, iterations = 1000L) stats::quantile(nd5, probs = c(0.025, 0.975))
Simulates the null distribution of the independence pivotal statistic
under plug-in sampling for releases.
Under the stacking result, the compound Wishart representation gives
where
and
.
Inddist(part, nsample, pvariates, iterations = 10000L, M = 1L)Inddist(part, nsample, pvariates, iterations = 10000L, M = 1L)
part |
Size of the first variable block, |
nsample |
Original sample size |
pvariates |
Total number of variables, |
iterations |
Number of Monte Carlo draws. The default is
|
M |
Number of synthetic releases. The default is |
A numeric vector of length iterations.
set.seed(1) nd1 <- Inddist( part = 2, nsample = 50, pvariates = 4, M = 1, iterations = 1000L ) stats::quantile(nd1, probs = 0.05) nd5 <- Inddist( part = 2, nsample = 50, pvariates = 4, M = 5, iterations = 1000L ) stats::quantile(nd5, probs = 0.05)set.seed(1) nd1 <- Inddist( part = 2, nsample = 50, pvariates = 4, M = 1, iterations = 1000L ) stats::quantile(nd1, probs = 0.05) nd5 <- Inddist( part = 2, nsample = 50, pvariates = 4, M = 5, iterations = 1000L ) stats::quantile(nd5, probs = 0.05)
Tests , that is, independence
between two subsets of variables, based on released plug-in
sampling synthetic data sets stacked into V. Setting
M = 1 recovers the single-release procedure of Klein et al.
(2021).
The two variable blocks can be specified in exactly one of two ways:
partAn integer scalar. The first part columns form Block 1, and
the remaining columns form Block 2. This is the original
backward-compatible interface.
group_a and group_b
Integer indices or column names identifying the two blocks. Together,
they must cover all columns of V exactly once. If names are
used, V must have column names.
independence_test( V, M = 1L, part = NULL, group_a = NULL, group_b = NULL, alpha = 0.05, iterations = 10000L, null_dist = NULL )independence_test( V, M = 1L, part = NULL, group_a = NULL, group_b = NULL, alpha = 0.05, iterations = 10000L, null_dist = NULL )
V |
Stacked synthetic data set, given as an |
M |
Positive integer giving the number of synthetic releases.
The default is |
part |
Integer scalar giving the size of Block 1. The first
|
group_a |
Integer indices or column names identifying Block 1. |
group_b |
Integer indices or column names identifying Block 2.
Together with |
alpha |
Significance level. The default is |
iterations |
Monte Carlo sample size used to approximate the
null distribution. The default is |
null_dist |
Optional numeric vector containing a precomputed null
distribution. If supplied, |
An object of class ps_test. The null hypothesis string
in $null.value names the two blocks explicitly.
Klein, M., Moura, R., and Sinha, B. (2021). Multivariate normal inference based on singly imputed synthetic data under plug-in sampling. Sankhya B, 83, 273–287. doi:10.1007/s13571-019-00215-9
data(brittany_soil_ps) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) # Integer interface independence_test(V5, M = 5, part = 2L, iterations = 1000L) # Named interface independence_test( V5, M = 5, group_a = c("pH_water", "pH_KCl", "log_CEC_Metson"), group_b = c("log_Organic_C", "log_Total_N", "log_P_Olsen"), iterations = 1000L )data(brittany_soil_ps) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) # Integer interface independence_test(V5, M = 5, part = 2L, iterations = 1000L) # Named interface independence_test( V5, M = 5, group_a = c("pH_water", "pH_KCl", "log_CEC_Metson"), group_b = c("log_Organic_C", "log_Total_N", "log_P_Olsen"), iterations = 1000L )
ps_test
Checks whether an object inherits from class ps_test.
is.ps_test(x)is.ps_test(x)
x |
Any R object. |
A logical value: TRUE if x inherits from class
ps_test, and FALSE otherwise.
data(brittany_soil_ps) set.seed(1) V <- simSynthData(brittany_soil_ps, M = 3) res <- sphericity_test(V, M = 3, iterations = 1000L) is.ps_test(res)data(brittany_soil_ps) set.seed(1) V <- simSynthData(brittany_soil_ps, M = 3) res <- sphericity_test(V, M = 3, iterations = 1000L) is.ps_test(res)
Assesses multivariate normality of a data set using five complementary approaches: (1) univariate Shapiro-Wilk tests on each variable, (2) Mardia's multivariate skewness test, (3) Mardia's multivariate kurtosis test, (4) the Henze-Zirkler omnibus test, and (5) Royston's multivariate extension of the Shapiro-Wilk test. A visual diagnostic panel shows one histogram with a fitted normal curve for each variable and a chi-square Q-Q plot of squared Mahalanobis distances.
mvn_test(X, alpha = 0.05, plot = TRUE, hz_nsim = 2000L, verbose = TRUE)mvn_test(X, alpha = 0.05, plot = TRUE, hz_nsim = 2000L, verbose = TRUE)
X |
A numeric matrix or data frame with dimension |
alpha |
Significance level for all tests. The default is |
plot |
Logical. If |
hz_nsim |
Integer. Number of Monte Carlo draws used to
calibrate the Henze-Zirkler null distribution. The default is |
verbose |
Logical. If |
Mardia's skewness test evaluates the null hypothesis of zero multivariate skewness:
Here
is a Mahalanobis inner product between observations and
. The indices and run over observations,
not variables.
Mardia's kurtosis test evaluates whether the multivariate
kurtosis equals :
The quantity is the squared Mahalanobis distance of
observation from the sample mean.
The Henze-Zirkler omnibus test is based on a weighted
distance between the empirical and theoretical
multivariate normal characteristic functions. The statistic is
where
The null distribution of is
approximated by a log-normal distribution whose parameters are
estimated by Monte Carlo simulation of size hz_nsim from
. This test is particularly
powerful useful against heavy-tailed and skewed alternatives.
Royston's H test extends the univariate Shapiro-Wilk statistic
to the multivariate setting. For each variable, the Shapiro-Wilk
-value is transformed to .
The test statistic is
where is an effective
degree of freedom parameter that accounts for correlation among the
values. The quantity estimated from the average
squared pairwise correlation of the original variables.
Diagnostic panel: The diagnostic panel contains plots
arranged in a grid. The first panels show histograms with fitted
density curves. The bar color is
steel-blue when the Shapiro-Wilk test fails to reject normality and tomato-red
when it rejects. The final panel shows the chi-square Q-Q plot of squared
Mahalanobis distances.
A list of class mvn_test, returned invisibly, with components:
Data frame of per-variable Shapiro-Wilk statistics
and -values.
Named list with components statistic,
df, p.value, and decision.
Named list with components statistic,
p.value, decision.
Named list Named list with components
statistic, p.value, decision.
Named list Named list with components statistic, the
Royston statistic; df, the effective degrees of freedom;
p.value, and decision.
Numeric vector of squared Mahalanobis distances.
Character string giving the overall conclusion based on all tests.
Mardia, K. V. (1970). Measures of multivariate skewness and kurtosis with applications. Biometrika, 57, 519–530.
Henze, N. and Zirkler, B. (1990). A class of invariant consistent tests for multivariate normality. Communications in Statistics: Theory and Methods, 19, 3595–3617.
Royston, J. P. (1992). Approximating the Shapiro-Wilk W test for non-normality. Statistics and Computing, 2, 117–119.
simSynthData,
brittany_soil_ps,
data(brittany_soil_ps) mvn_test(brittany_soil_ps)data(brittany_soil_ps) mvn_test(brittany_soil_ps)
Tests using the original data matrix
X. The null value Sigma0 is typically supplied by the
user.
If Sigma0 = cov(X), the null determinant is estimated from the
same data used to compute the test statistic. In that case, the
determinant ratio is one, the chi-square statistic is zero, and the
-value is one by construction.
Supplying a different Sigma0 gives a likelihood-ratio
chi-square test with Bartlett correction.
The test statistic is
referred to a distribution with
degrees of freedom.
original_gv_test(X, Sigma0 = NULL, alpha = 0.05)original_gv_test(X, Sigma0 = NULL, alpha = 0.05)
X |
Original data matrix with dimension |
Sigma0 |
A |
alpha |
Significance level. The default is |
A list with components:
statisticObserved statistic.
p.value-value.
dfDegrees of freedom, .
det.Sigma.hatValue of .
decisionCharacter string: "Reject H0" or
"Fail to reject H0".
alphaSignificance level used.
n, p
Sample size and number of variables.
Anderson, T. W. (1984). An Introduction to Multivariate Statistical Analysis (2nd ed.). John Wiley & Sons, New York.
data(brittany_soil_ps) X <- brittany_soil_ps ## Null = MLE => p-value = 1 by construction original_gv_test(X) ## Test against a specific null Sigma0 <- diag(ncol(X)) original_gv_test(X, Sigma0 = Sigma0)data(brittany_soil_ps) X <- brittany_soil_ps ## Null = MLE => p-value = 1 by construction original_gv_test(X) ## Test against a specific null Sigma0 <- diag(ncol(X)) original_gv_test(X, Sigma0 = Sigma0)
Tests , corresponding to block
independence, using Bartlett's factored-likelihood chi-square
approximation applied to the original data matrix X.
The Wilks statistic is
and the test statistic is
referred to a distribution with degrees
of freedom.
original_independence_test( X, part = NULL, group_a = NULL, group_b = NULL, alpha = 0.05 )original_independence_test( X, part = NULL, group_a = NULL, group_b = NULL, alpha = 0.05 )
X |
Original data matrix with dimension |
part |
Integer scalar. The first |
group_a |
Integer indices or column names identifying Block 1. |
group_b |
Integer indices or column names identifying Block 2. |
alpha |
Significance level. The default is |
A list with components statistic (),
p.value, df, Lambda (Wilks statistic),
decision, alpha, n, p, p1,
p2, lbl1, and lbl2.
Anderson, T. W. (1984). An Introduction to Multivariate Statistical Analysis (2nd ed.). John Wiley & Sons, New York.
data(brittany_soil_ps) original_independence_test(brittany_soil_ps, group_a = c("pH_water", "pH_KCl"), group_b = c( "log_CEC_Metson", "log_Organic_C", "log_Total_N", "log_P_Olsen" ) )data(brittany_soil_ps) original_independence_test(brittany_soil_ps, group_a = c("pH_water", "pH_KCl"), group_b = c( "log_CEC_Metson", "log_Organic_C", "log_Total_N", "log_P_Olsen" ) )
Tests for the population regression
matrix , using Rao's
-approximation to Wilks' statistic applied to
the original data matrix X.
The Wilks statistic is
where
is the residual Schur complement under . This equals the
ordinary Schur complement when
, giving and
by construction. The default Delta0 = NULL tests
, corresponding to zero regression.
original_regression_test( X, part = NULL, Delta0 = NULL, response = NULL, predictors = NULL, alpha = 0.05 )original_regression_test( X, part = NULL, Delta0 = NULL, response = NULL, predictors = NULL, alpha = 0.05 )
X |
Original data matrix with dimension |
part |
Integer scalar giving the size of the response block
(Block 1). The first |
Delta0 |
A |
response |
Integer or character vector identifying the response block. |
predictors |
Integer or character vector identifying the predictor block. |
alpha |
Significance level. The default is |
A list with components statistic (), p.value,
df1, df2, Lambda, Delta.hat
(),
decision, alpha, n, p, p1,
p2, lbl1, and lbl2.
Anderson, T. W. (1984). An Introduction to Multivariate Statistical Analysis (2nd ed.). John Wiley & Sons, New York.
Rao, C. R. (1951). An asymptotic expansion of the distribution of Wilks' criterion. Bulletin of the International Statistical Institute, 33, 177–180.
data(brittany_soil_ps) X <- brittany_soil_ps ## Test H0: Delta = 0 (default) original_regression_test(X, response = c("pH_water", "pH_KCl"), predictors = c( "log_CEC_Metson", "log_Organic_C", "log_Total_N", "log_P_Olsen" ) ) ## Test H0: Delta = Delta_hat (MLE) => F = 0, p = 1 by construction blk <- partition(cov(X), part1 = c("pH_water", "pH_KCl")) Delta0 <- blk$B %*% solve(blk$D) original_regression_test(X, response = c("pH_water", "pH_KCl"), predictors = c( "log_CEC_Metson", "log_Organic_C", "log_Total_N", "log_P_Olsen" ), Delta0 = Delta0 )data(brittany_soil_ps) X <- brittany_soil_ps ## Test H0: Delta = 0 (default) original_regression_test(X, response = c("pH_water", "pH_KCl"), predictors = c( "log_CEC_Metson", "log_Organic_C", "log_Total_N", "log_P_Olsen" ) ) ## Test H0: Delta = Delta_hat (MLE) => F = 0, p = 1 by construction blk <- partition(cov(X), part1 = c("pH_water", "pH_KCl")) Delta0 <- blk$B %*% solve(blk$D) original_regression_test(X, response = c("pH_water", "pH_KCl"), predictors = c( "log_CEC_Metson", "log_Organic_C", "log_Total_N", "log_P_Olsen" ), Delta0 = Delta0 )
Tests using the Bartlett-Box
chi-square approximation applied to the original data matrix X.
The Mauchly statistic is
and the test statistic is
referred to a distribution with
degrees of freedom.
original_sphericity_test(X, alpha = 0.05)original_sphericity_test(X, alpha = 0.05)
X |
Original data matrix with dimension |
alpha |
Significance level. The default is |
A list with components statistic (),
p.value, df, W (Mauchly statistic),
sigma2.hat (plug-in estimate
), decision,
alpha, n, and p.
Anderson, T. W. (1984). An Introduction to Multivariate Statistical Analysis (2nd ed.). John Wiley & Sons, New York.
Bartlett, M. S. (1954). A note on the multiplying factors for various chi-square approximations. Journal of the Royal Statistical Society: Series B, 16, 296–298.
data(brittany_soil_ps) original_sphericity_test(brittany_soil_ps)data(brittany_soil_ps) original_sphericity_test(brittany_soil_ps)
Splits a numeric matrix into four submatrices according
to a two-group partition of its rows and columns:
The blocks are:
Rows in the first group and columns in the first group.
Rows in the first group and columns in the second group.
Rows in the second group and columns in the first group.
Rows in the second group and columns in the second group.
Two interfaces are available:
Supply nrows and ncols. The first nrows rows
and the first ncols columns form the first block.
Supply part1 as a character vector of row and column names.
This interface is intended for square matrices, such as covariance
or correlation matrices. The matrix is reordered so that the
part1 rows and columns appear first. The optional
part2 argument is checked against the complement of
part1.
partition(Matrix, nrows = NULL, ncols = NULL, part1 = NULL, part2 = NULL)partition(Matrix, nrows = NULL, ncols = NULL, part1 = NULL, part2 = NULL)
Matrix |
A numeric matrix. When using the name interface, it must be a square matrix with matching row and column names. |
nrows |
Integer giving the number of rows in the first row block.
Ignored when |
ncols |
Integer giving the number of columns in the first column
block. Ignored when |
part1 |
Character vector of names forming the first group. Used for both row and column reordering in the name interface. |
part2 |
Optional character vector naming the second group. If
supplied, it is checked against the complement of |
A named list of class "ps_partition" with elements A,
B, C, and D. Numeric indexing with
[[1]] through [[4]] also works.
M <- matrix( 1:16, 4, 4, dimnames = list(c("A", "B", "C", "D"), c("A", "B", "C", "D")) ) # Integer interface b <- partition(M, nrows = 2, ncols = 2) b$A # Name interface b2 <- partition(M, part1 = c("A", "B")) b2$A b2$D # Covariance matrix example data(brittany_soil_ps) b3 <- partition( cov(brittany_soil_ps), part1 = c("log_Organic_C", "log_Total_N", "log_P_Olsen"), part2 = c("pH_water", "pH_KCl", "log_CEC_Metson") ) b3$A b3$DM <- matrix( 1:16, 4, 4, dimnames = list(c("A", "B", "C", "D"), c("A", "B", "C", "D")) ) # Integer interface b <- partition(M, nrows = 2, ncols = 2) b$A # Name interface b2 <- partition(M, part1 = c("A", "B")) b2$A b2$D # Covariance matrix example data(brittany_soil_ps) b3 <- partition( cov(brittany_soil_ps), part1 = c("log_Organic_C", "log_Total_N", "log_P_Olsen"), part2 = c("pH_water", "pH_KCl", "log_CEC_Metson") ) b3$A b3$D
mvn_test ObjectsRe-draws the chi-square Q-Q diagnostic. For the full histogram panel,
call mvn_test(X, plot = TRUE) on the original data directly.
## S3 method for class 'mvn_test' plot(x, ...)## S3 method for class 'mvn_test' plot(x, ...)
x |
An object of class |
... |
Further arguments (currently ignored). |
Invisibly returns x.
ps_test ObjectProduces a density plot of the simulated null distribution with the observed test statistic and critical value(s) marked. The rejection region is shaded.
The x-axis always includes both the null distribution and the observed
statistic. For the generalized variance and regression tests, a
log10 scale is used automatically because these statistics may span
several orders of magnitude. Key information is placed below the plot
as text so it does not overlap the density curve. The function is
multi-panel aware: inside par(mfrow = ...), it uses compact
in-plot annotations and does not modify the outer margins.
## S3 method for class 'ps_test' plot( x, main = NULL, shade_col = grDevices::adjustcolor("tomato", 0.45), dist_col = grDevices::adjustcolor("steelblue", 0.22), stat_col = "firebrick", crit_col = "steelblue4", ... )## S3 method for class 'ps_test' plot( x, main = NULL, shade_col = grDevices::adjustcolor("tomato", 0.45), dist_col = grDevices::adjustcolor("steelblue", 0.22), stat_col = "firebrick", crit_col = "steelblue4", ... )
x |
An object of class |
main |
Optional title string. If |
shade_col |
Color for the rejection-region shading. |
dist_col |
Color for the null-distribution density fill. |
stat_col |
Color for the observed-statistic line. |
crit_col |
Color for the critical-value line(s). |
... |
Further arguments passed to |
Invisibly returns x.
data(brittany_soil_ps) V <- simSynthData(brittany_soil_ps, M = 3) plot(sphericity_test(V, M = 3))data(brittany_soil_ps) V <- simSynthData(brittany_soil_ps, M = 3) plot(sphericity_test(V, M = 3))
mvn_test ObjectsPrint the result of the test.
## S3 method for class 'mvn_test' print(x, ...)## S3 method for class 'mvn_test' print(x, ...)
x |
An object of class |
... |
Further arguments (currently ignored). |
Invisibly returns x.
original_test ObjectPrints a concise summary of a classical test result.
## S3 method for class 'original_test' print(x, ...)## S3 method for class 'original_test' print(x, ...)
x |
An object of class |
... |
Further arguments, currently ignored. |
Invisibly returns x.
ps_test ObjectPrints a concise, human-readable summary of the test result stored in
a ps_test object.
## S3 method for class 'ps_test' print(x, ...)## S3 method for class 'ps_test' print(x, ...)
x |
An object of class |
... |
Further arguments, currently ignored. |
Invisibly returns x.
data(brittany_soil_ps) set.seed(1) V <- simSynthData(brittany_soil_ps, M = 3) res <- sphericity_test(V, M = 3, iterations = 1000L) print(res)data(brittany_soil_ps) set.seed(1) V <- simSynthData(brittany_soil_ps, M = 3) res <- sphericity_test(V, M = 3, iterations = 1000L) print(res)
ps_utility ObjectsPrints a formatted summary of the five headline utility measures returned
by utility_measures.
## S3 method for class 'ps_utility' print(x, ...)## S3 method for class 'ps_utility' print(x, ...)
x |
An object of class |
... |
Further arguments, currently ignored. |
Invisibly returns x.
Dispatches to the appropriate exact inferential procedure based on the
test argument and can optionally produce the diagnostic plot
immediately. This is the main entry point for users who prefer a single
function instead of calling the four individual test functions directly.
ps_test( V, M = 1L, test = c("gv", "sphericity", "independence", "regression"), plot = FALSE, ... )ps_test( V, M = 1L, test = c("gv", "sphericity", "independence", "regression"), plot = FALSE, ... )
V |
Stacked synthetic data set, given as an |
M |
Positive integer giving the number of synthetic releases. The
default is |
test |
Character string specifying the test. One of
|
plot |
Logical. If |
... |
Additional arguments passed to the corresponding test
function or, when |
An object of class ps_test-class, invisibly when
plot = TRUE.
gv_test,
sphericity_test,
independence_test,
regression_test
data(brittany_soil_ps) set.seed(1) V <- simSynthData(brittany_soil_ps, M = 3) # Run and print only ps_test(V, M = 3, test = "sphericity", iterations = 1000L) # Run and plot in one call ps_test(V, M = 3, test = "sphericity", iterations = 1000L, plot = TRUE ) # Independence with named blocks ps_test( V, M = 3, test = "independence", group_a = c("log_Organic_C", "log_Total_N", "log_P_Olsen"), group_b = c("pH_water", "pH_KCl", "log_CEC_Metson"), iterations = 1000L, plot = TRUE ) # Generalized variance with a reference covariance matrix ps_test( V, M = 3, test = "gv", Sigma = cov(brittany_soil_ps), iterations = 1000L, plot = TRUE )data(brittany_soil_ps) set.seed(1) V <- simSynthData(brittany_soil_ps, M = 3) # Run and print only ps_test(V, M = 3, test = "sphericity", iterations = 1000L) # Run and plot in one call ps_test(V, M = 3, test = "sphericity", iterations = 1000L, plot = TRUE ) # Independence with named blocks ps_test( V, M = 3, test = "independence", group_a = c("log_Organic_C", "log_Total_N", "log_P_Olsen"), group_b = c("pH_water", "pH_KCl", "log_CEC_Metson"), iterations = 1000L, plot = TRUE ) # Generalized variance with a reference covariance matrix ps_test( V, M = 3, test = "gv", Sigma = cov(brittany_soil_ps), iterations = 1000L, plot = TRUE )
The ps_test class is the unified output object returned by the
inferential functions in PSinference. It stores the test result,
the simulated null distribution, and relevant metadata, and provides
print, summary, and plot methods for convenient
inspection and reporting.
Numeric. Observed value of the test statistic.
Numeric. Monte Carlo p-value.
Numeric. Significance level used.
Character. "Reject H0" or
"Fail to reject H0".
Numeric vector. Simulated null distribution.
Character. One of "gv", "sphericity",
"independence", "regression".
Integer. Original sample size.
Integer. Number of synthetic releases.
Integer. Effective sample size .
Integer. Number of variables.
Numeric vector of length 2 or NULL.
Confidence interval (generalized variance only).
Numeric or NULL. Plug-in estimator of
(sphericity only).
Matrix or NULL. Plug-in estimator of
, used for the regression test.
Character or NULL. Label for the first variable
block, used by block-based tests.
Character or NULL. Label for the second variable
block, used by block-based tests.
Integer. Number of Monte Carlo iterations used to calibrate the null distribution.
Tests for the population regression
matrix , based on
released plug-in sampling synthetic data sets stacked into V.
The test requires . Setting M = 1 recovers
the single-release procedure of Klein et al. (2021).
The two variable blocks can be specified in exactly one of two ways:
partAn integer scalar. The first part columns form the response
block, and the remaining columns form the predictor block. This is
the original backward-compatible interface.
response and predictors
Integer indices or column names identifying the response and
predictor blocks. Together, they must cover all columns of
V exactly once.
regression_test( V, M = 1L, part = NULL, Delta0 = NULL, response = NULL, predictors = NULL, alpha = 0.05, iterations = 10000L, null_dist = NULL )regression_test( V, M = 1L, part = NULL, Delta0 = NULL, response = NULL, predictors = NULL, alpha = 0.05, iterations = 10000L, null_dist = NULL )
V |
Stacked synthetic data set, given as an |
M |
Positive integer giving the number of synthetic releases.
The default is |
part |
Integer scalar giving the size of the response block.
The first |
Delta0 |
A |
response |
Integer or character vector identifying the response block. |
predictors |
Integer or character vector identifying the predictor
block. Together with |
alpha |
Significance level. The default is |
iterations |
Monte Carlo sample size used to approximate the
null distribution. The default is |
null_dist |
Optional numeric vector containing a precomputed null
distribution. If supplied, |
An object of class ps_test. Component Delta.hat
gives the plug-in slope estimator
.
The null hypothesis string in $null.value names both blocks.
Klein, M., Moura, R., and Sinha, B. (2021). Multivariate normal inference based on singly imputed synthetic data under plug-in sampling. Sankhya B, 83, 273–287. doi:10.1007/s13571-019-00215-9
data(brittany_soil_ps) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) # Integer interface: zero regression regression_test(V5, M = 5, part = 2L, iterations = 1000L) # Named interface with Delta0 estimated from the original data S0 <- cov(brittany_soil_ps) response <- c("pH_water", "pH_KCl", "log_CEC_Metson") predictors <- c("log_Organic_C", "log_Total_N", "log_P_Olsen") b <- partition(S0, part1 = response, part2 = predictors ) Delta0 <- b$B %*% solve(b$D) regression_test( V5, M = 5, response = response, predictors = predictors, Delta0 = Delta0, iterations = 1000L )data(brittany_soil_ps) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) # Integer interface: zero regression regression_test(V5, M = 5, part = 2L, iterations = 1000L) # Named interface with Delta0 estimated from the original data S0 <- cov(brittany_soil_ps) response <- c("pH_water", "pH_KCl", "log_CEC_Metson") predictors <- c("log_Organic_C", "log_Total_N", "log_P_Olsen") b <- partition(S0, part1 = response, part2 = predictors ) Delta0 <- b$B %*% solve(b$D) regression_test( V5, M = 5, response = response, predictors = predictors, Delta0 = Delta0, iterations = 1000L )
Generates independent fully synthetic data sets from an
original numeric matrix X using the plug-in sampling (PS)
mechanism under a multivariate normal model. The synthetic observations
are returned as a single stacked matrix.
The unknown population parameters and
are replaced by the sample mean
and sample covariance matrix
. Then synthetic observations
are drawn independently from
.
Setting M = 1 produces a single synthetic data set of size
, corresponding to the classical single-release PS procedure of
Klein et al. (2021). Setting M > 1 produces the stacked data set
used by the multiple-release
procedures:
simSynthData(X, M = 1L)simSynthData(X, M = 1L)
X |
A numeric matrix or data frame containing the original
confidential observations. Rows are observations and columns are
variables. The input must have dimension |
M |
A positive integer giving the number of independent synthetic
releases to generate. The default is |
The stacked representation is statistically justified because all
rows are conditionally independent and identically distributed
given the original data. Thus, the stacked sufficient statistic
satisfies
An numeric matrix. Column names are preserved from
X. For M = 1, row names are preserved from X when
available. For M > 1, row names encode the release index and
observation index using the form "release_j.obs_i".
Klein, M., Moura, R., and Sinha, B. (2021). Multivariate normal inference based on singly imputed synthetic data under plug-in sampling. Sankhya B, 83, 273–287. doi:10.1007/s13571-019-00215-9
ps_test,
gv_test,
sphericity_test,
independence_test,
regression_test
data(brittany_soil_ps) # Single release: M = 1 set.seed(1) V1 <- simSynthData(brittany_soil_ps) dim(V1) # Five releases stacked row-wise set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) dim(V5)data(brittany_soil_ps) # Single release: M = 1 set.seed(1) V1 <- simSynthData(brittany_soil_ps) dim(V1) # Five releases stacked row-wise set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) dim(V5)
Simulates the null distribution of the sphericity pivotal statistic
under plug-in sampling for releases.
Under the stacking result, the compound Wishart representation gives
where
and
independently.
For , both Wishart distributions have degrees of freedom
, recovering the single-release result of Klein et al.
(2021).
Sphdist(nsample, pvariates, iterations = 10000L, M = 1L)Sphdist(nsample, pvariates, iterations = 10000L, M = 1L)
nsample |
Original sample size |
pvariates |
Number of variables |
iterations |
Number of Monte Carlo draws. The default is
|
M |
Number of synthetic releases. The default is |
A numeric vector of length iterations.
set.seed(1) nd1 <- Sphdist(nsample = 50, pvariates = 4, M = 1, iterations = 1000L) stats::quantile(nd1, probs = 0.05) nd5 <- Sphdist(nsample = 50, pvariates = 4, M = 5, iterations = 1000L) stats::quantile(nd5, probs = 0.05)set.seed(1) nd1 <- Sphdist(nsample = 50, pvariates = 4, M = 1, iterations = 1000L) stats::quantile(nd1, probs = 0.05) nd5 <- Sphdist(nsample = 50, pvariates = 4, M = 5, iterations = 1000L) stats::quantile(nd5, probs = 0.05)
Tests , that is, all variables uncorrelated
with equal variance. The test is based on released plug-in sampling
synthetic data sets stacked into V. The test is left-tailed. Setting
M = 1 recovers the single-release procedure of Klein et al. (2021).
sphericity_test(V, M = 1L, alpha = 0.05, iterations = 10000L, null_dist = NULL)sphericity_test(V, M = 1L, alpha = 0.05, iterations = 10000L, null_dist = NULL)
V |
Stacked synthetic data set, given as an |
M |
Positive integer giving the number of synthetic releases.
The default is |
alpha |
Significance level. The default is |
iterations |
Monte Carlo sample size used to approximate the
null distribution. The default is |
null_dist |
Optional numeric vector containing a precomputed null
distribution. If supplied, |
An object of class ps_test. Component
sigma2.hat gives the plug-in estimator
under .
Klein, M., Moura, R., and Sinha, B. (2021). Multivariate normal inference based on singly imputed synthetic data under plug-in sampling. Sankhya B, 83, 273–287. doi:10.1007/s13571-019-00215-9
data(brittany_soil_ps) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) res <- sphericity_test(V5, M = 5, iterations = 1000L) print(res) plot(res)data(brittany_soil_ps) set.seed(1) V5 <- simSynthData(brittany_soil_ps, M = 5) res <- sphericity_test(V5, M = 5, iterations = 1000L) print(res) plot(res)
ps_test ObjectPrints a detailed summary including the null-distribution quantiles and a comparison with the observed statistic.
## S3 method for class 'ps_test' summary(object, ...)## S3 method for class 'ps_test' summary(object, ...)
object |
An object of class |
... |
Further arguments, currently ignored. |
Invisibly returns object.
data(brittany_soil_ps) V <- simSynthData(brittany_soil_ps, M = 3) res <- sphericity_test(V, M = 3) summary(res)data(brittany_soil_ps) V <- simSynthData(brittany_soil_ps, M = 3) res <- sphericity_test(V, M = 3) summary(res)
Computes five complementary utility measures quantifying how well plug-in
sampling (PS) synthetic data preserve the statistical properties of the
original confidential data. The reported headline measures are Frobenius
distance, mean standardized mean difference, variance ratio range,
propensity score MSE (pMSE) ratio, and mean confidence interval overlap.
For releases, per-release statistics are computed and averaged
where appropriate.
utility_measures(X, V, M = 1L, alpha = 0.05, verbose = TRUE)utility_measures(X, V, M = 1L, alpha = 0.05, verbose = TRUE)
X |
A numeric matrix or data frame with dimension |
V |
A numeric matrix or data frame with dimension |
M |
Positive integer giving the number of synthetic releases. The
default is |
alpha |
Significance level used for confidence interval overlap. The
default is |
verbose |
Logical. If |
The Frobenius distance measures covariance matrix preservation:
For , is the
average per-release sample covariance matrix.
The mean standardized mean difference is
Values below 0.10 indicate negligible marginal mean differences.
The variance ratio range is
Values close to 1 indicate good variance preservation.
The original data, labeled 0, and the synthetic data, labeled 1, are combined. A logistic classifier is fitted to distinguish original from synthetic records. The pMSE is
The expected value under a correctly specified synthesis model is
The pMSE ratio is
Values near 1 indicate good utility, whereas values well below 1 indicate that the synthetic data blend in well with the original data.
For each variable , a confidence interval (CI) is
computed from the original data and from the synthetic data. The overlap
coefficient is
where and are the CIs
from original and synthetic data. The reported measure is the average
of across all variables.
A list of class ps_utility, returned invisibly, with components:
Numeric. Frobenius distance
.
Numeric. Mean standardized mean difference,
.
Named numeric vector with the minimum and maximum per-variable variance ratios.
Numeric. Ratio pmse / pmse_null.
Numeric. Mean confidence interval overlap across all variables.
Integer. Number of synthetic releases.
Integer. Original sample size.
Integer. Number of variables.
Numeric. Significance level used.
Karr, A. F., Kohnen, C. N., Oganian, A., Reiter, J. P., and Sanil, A. P. (2006). A framework for evaluating the utility of data altered to protect confidentiality. The American Statistician, 60, 224–232.
Snoke, J., Raab, G. M., Nowok, B., Dibben, C., and Slavkovic, A. (2018). General and specific utility measures for synthetic data. Journal of the Royal Statistical Society: Series A, 181, 663–688.
Woo, M.-J., Reiter, J. P., Oganian, A., and Karr, A. F. (2009). Global measures of data utility for microdata masked for disclosure limitation. Journal of Privacy and Confidentiality, 1, 111–124.
data(brittany_soil_ps) set.seed(1) V3 <- simSynthData(brittany_soil_ps, M = 3) utility_measures(brittany_soil_ps, V3, M = 3)data(brittany_soil_ps) set.seed(1) V3 <- simSynthData(brittany_soil_ps, M = 3) utility_measures(brittany_soil_ps, V3, M = 3)