Type: | Package |
Title: | Statistics for International Large-Scale Assessments (ILSA) |
Version: | 0.4.0 |
Maintainer: | Andrés Christiansen <andres.christiansen@iea-hamburg.de> |
Description: | Calculates point estimates and standard errors using replicate weights and plausible values for International Large-Scale Assessments (ILSA), including: means, proportions, quantiles, correlations, singlelevel regressions, and multilevel regressions. |
Encoding: | UTF-8 |
LazyData: | true |
LazyDataCompression: | xz |
RoxygenNote: | 7.3.2 |
Suggests: | wCorr, lme4, MuMIn, WeMix |
Depends: | R (≥ 3.5.0) |
License: | GPL (≥ 3) |
NeedsCompilation: | no |
Packaged: | 2025-07-15 23:28:09 UTC; andreschristiansen |
Author: | Andrés Christiansen
|
Repository: | CRAN |
Date/Publication: | 2025-07-15 23:40:08 UTC |
ILSA information
Description
ILSA information
Survey Weighted Mixed-Effects Models with Plausible Values
Description
Fits a linear mixed-effects model using mix and plausible values.
Usage
WeMixPV(formula, data = NULL, weights = NULL, pvs, relatedpvs = TRUE, ...)
Arguments
formula |
a formula object in the style of |
data |
a data frame containing the raw data for the model. |
weights |
a character vector of names of weight variables found in the data frame starts with units (level 1) and increasing (larger groups). |
pvs |
a list indicating which variables from |
relatedpvs |
a logical value indicating if |
... |
Arguments passed on to
|
Value
a list.
Examples
# Prepare data weights
repdata2 <- repdata
repdata2$wt1 <- repdata2$wt # weight level 1
repdata2$wt2 <- 1 # weight level 2
# Null model - with PVs
## Named list, with element names matching formula variables
pvs = list(MATH = paste0("Math",1:5))
m1 <- WeMixPV(formula = MATH ~ 1 + (1|GROUP), # Intercept varies across GROUP
pvs = pvs, # Named list
data = repdata2, # Data frame
weights = c("wt1","wt2")) # Weights vector
m1
## Fixed effects
m1$fixef
## Random effects
m1$ranef
## Models for each PV
summary(m1$models)
# Multiple regression
## Named list, with element names matching formula variables
pvs = list(MATH = paste0("Math",1:5))
m2 <- WeMixPV(formula = MATH ~ 1 + GENDER + SES + schoolSES + (1|GROUP),
pvs = pvs, # Named list
data = repdata2, # Data frame
weights = c("wt1","wt2")) # Weights vector
m2
Centering
Description
Centers a vector, a matrix or a data frame to the grand mean or the group mean.
Usage
center(X, group = NULL, grandmean = NULL, groupmean = NULL, wt = NULL)
grand.mean(x, wt = NULL)
group.mean(x, group, wt = NULL)
getgroup.mean(x, group, wt = NULL)
Arguments
X |
a matrix or a data frame. |
group |
a vector indicating the group for centering. |
grandmean |
a numeric or character vector indicating the number or the
the names of columns of |
groupmean |
a numeric or character vector indicating the number or the
the names of columns of |
wt |
a numeric vector of weights. |
x |
a vector, a matrix or a data frame. |
Value
a data frame, or a vector.
Examples
# Less data for shorter example
repdata2 <- repdata[1:10,c(1:3,6:10,51)]
### One variable ----
# grand-mean
grand.mean(repdata2$item01)
grand.mean(repdata2$item01,wt = repdata2$wt)
# group-mean
group.mean(repdata2$item01,group = repdata2$GROUP)
group.mean(repdata2$item01,group = repdata2$GROUP,wt = repdata2$wt)
### More than one variable with the same rule ----
# grand-mean
grand.mean(repdata2[,4:8])
grand.mean(repdata2[,4:8],wt = repdata2$wt)
# group-mean
group.mean(repdata2[,4:8],group = repdata2$GROUP)
group.mean(repdata2[,4:8],group = repdata2$GROUP,wt = repdata2$wt)
### More than one variable with different rules ----
center(repdata2, group = repdata2$GROUP, grandmean = 4:5, groupmean = 6:8, wt = repdata2$wt)
center(repdata2, group = repdata2$GROUP, grandmean = 6:8, groupmean = 4:5, wt = repdata2$wt)
center(repdata2, group = repdata2$GROUP, wt = repdata2$wt,
grandmean = paste0("item0",1:3), groupmean = paste0("item0",4:5))
center(repdata2, group = repdata2$GROUP, wt = repdata2$wt,
grandmean = paste0("item0",4:5), groupmean = paste0("item0",1:3))
Intraclass Correlation Coefficient
Description
Calculates the intraclass correlation coefficient (ICC) fitting a linear mixed-effects model using lmer.
Usage
icc(x, PV = FALSE, group, data, weights = NULL, ...)
Arguments
x |
a string vector specifying variable names (within |
PV |
a logical value indicating if the variables in |
group |
a string specifying the variable name (within |
data |
an optional data frame containing the variables named in
|
weights |
an optional vector of ‘prior weights’ to be used
in the fitting process. Should be |
... |
Arguments passed on to
|
Value
a numeric value or a list.
Examples
# ICC of one variable
icc(x = "Math1",group = "GROUP", weights = repdata$wt, data = repdata)
# ICC of more than one variable
icc(x = c("Math1","Math2","Math3","Math4","Math5","SES"),
group = "GROUP", weights = repdata$wt, data = repdata)
# ICC of PVs
icc(x = c("Math1","Math2","Math3","Math4","Math5"), PV = TRUE,
group = "GROUP", weights = repdata$wt, data = repdata)
Linear Mixed-Models with Plausible Values
Description
Fits a linear mixed-effects model using lmer and plausible values.
Usage
lmerPV(
formula,
data = NULL,
weights = NULL,
pvs,
relatedpvs = TRUE,
grandmean = NULL,
groupmean = NULL,
group = NULL,
nullmodel = FALSE,
...
)
Arguments
formula |
a two-sided linear formula object describing both the
fixed-effects and random-effects part of the model, with the
response on the left of a |
data |
an optional data frame containing the variables named in
|
weights |
an optional vector of ‘prior weights’ to be used
in the fitting process. Should be |
pvs |
a list indicating which variables from |
relatedpvs |
a logical value indicating if |
grandmean |
a character vector indicating the names of columns of
|
groupmean |
a character vector indicating the names of columns of
|
group |
a string specifying the variable name (within |
nullmodel |
a logical value indicating if the null model should also be estimated. |
... |
Arguments passed on to
|
Value
a list.
Examples
# Null model - with PVs
## Named list, with element names matching formula variables
pvs = list(MATH = paste0("Math",1:5))
m1 <- lmerPV(formula = MATH ~ 1 + (1|GROUP), # Intercept varies across GROUP
pvs = pvs, # Named list
data = repdata, # Data frame
weights = repdata$wt) # Weights vector
m1
## Fixed effects
m1$fixef
## Random effects
m1$ranef
## Models for each PV
summary(m1$models)
# Multiple regression
## Named list, with element names matching formula variables
pvs = list(MATH = paste0("Math",1:5))
m2 <- lmerPV(formula = MATH ~ 1 + GENDER + SES + schoolSES + (1|GROUP),
pvs = pvs, # Named list
data = repdata, # Data frame
weights = repdata$wt) # Weights vector
m2
# Multiple regression with grandmean centering
## Named list, with element names matching formula variables
pvs = list(MATH = paste0("Math",1:5))
m3 <- lmerPV(formula = MATH ~ 1 + GENDER + SES + schoolSES + (1|GROUP),
pvs = pvs, # Named list
data = repdata, # Data frame
weights = repdata$wt,
grandmean = c("SES","schoolSES"))
m3
# Multiple regression with groupmean centering
## Named list, with element names matching formula variables
pvs = list(MATH = paste0("Math",1:5))
m4 <- lmerPV(formula = MATH ~ 1 + GENDER + SES + schoolSES + (1|GROUP),
pvs = pvs, # Named list
data = repdata, # Data frame
weights = repdata$wt,
grandmean = "schoolSES",
groupmean = "SES",
group = repdata$GROUP)
m4
My Wrapper Function
Description
My Wrapper Function
Usage
myfunc(x, method = formals(repse)$method, setup = formals(repse)$setup, ...)
Arguments
x |
Main input parameter |
method , setup |
Parameters passed to [repse()]. Defaults: - method: 'r eval(formals(repse)$method)' - setup: 'r eval(formals(repse)$setup)' |
... |
Additional arguments passed to [repse()] |
Value
Description of return value
Creation of Replicate Weights
Description
Creates replicate weights given jackknife replicates and jackknife zones.
Usage
repcreate(df, wt, jkzone, jkrep, repwtname = "RWT", reps = NULL, method)
repcreateILSA(study, year, df, repwtname = "RWT")
Arguments
df |
a data frame. |
wt |
a string specifying the name of the column (within |
jkzone |
a string specifying the name of the column in |
jkrep |
a string specifying the name of the column in |
repwtname |
a string specifying the variable names for the replicate weights. |
reps |
an integer indicating the number of replications to be created.
If |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
study |
a string indicating the study name. For checking available studies use
|
year |
a numeric value indicating the study year. For checking available
years use
|
Value
a data frame.
Examples
head(repdata)
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
head(RW)
Simulated data with 5000 cases
Description
Simulated data with 5000 cases
Generalized Linear Models with Replicate Weights
Description
Fits a generalized linear model using glm for replicate weights.
For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
repglm(
formula,
family = stats::gaussian,
pvs = NULL,
relatedpvs = TRUE,
quiet = FALSE,
summarize = TRUE,
setup = NULL,
df,
wt,
repwt,
group = NULL,
exclude = NULL,
na.action = getOption("na.action"),
method
)
Arguments
formula |
an object of class |
family |
a description of the error distribution and link
function to be used in the model. For |
pvs |
if plausible values are not used, this should be |
relatedpvs |
a logical value indicating if |
quiet |
a logical value indicating if progress status should be shown
while estimating models by group. Default is |
summarize |
a logical value indicating if |
setup |
an optional list produced by |
df |
a data frame. |
wt |
a string specifying the name of the column (within |
repwt |
a string indicating the common names for the replicate weights
columns (within |
group |
a string specifying the variable name (within |
exclude |
a vector indicating which groups
(in the same format as |
na.action |
a function which indicates what should happen
when the data contain |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
Value
a list with the standard errors and the total weights models.
Examples
# Less data for shorter example
repdata2 <- repdata[1:1000,]
RW <- repcreate(df = repdata2, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
# Simple regression - weights within df
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = "REPWT", # Common names of replicate weights within df
df = cbind(repdata2,RW), # Data frame
method = "ICILS") # the name of the method aka the study name
# Simple regression - weights as a separate data frame
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
method = "ICILS") # the name of the method aka the study name
# Multiple regression
replm(formula = Math1 ~ 1 + GENDER + Reading1,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with PVs
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading1, # Math1 now is "Math"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with more than one related PV variable
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with more than UNrelated PV variables
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
relatedpvs = FALSE, # Unrelated PVs
method = "ICILS") # the name of the method aka the study name
### Groups ----
# Simple regression - weights within df
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = "REPWT", # Common names of replicate weights within df
df = cbind(repdata2,RW), # Data frame
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Simple regression - weights as a separate data frame
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression
replm(formula = Math1 ~ 1 + GENDER + Reading1,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with PVs
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading1, # Math1 now is "Math"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with more than one related PV variable
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with UNrelated PV variables
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
relatedpvs = FALSE, # Unrelated PVs
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
Linear Models with Replicate Weights
Description
Fits a linear model using lm for replicate weights.
For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
replm(
formula,
pvs = NULL,
relatedpvs = TRUE,
quiet = FALSE,
summarize = TRUE,
setup = NULL,
df,
wt,
repwt,
group = NULL,
exclude = NULL,
na.action = getOption("na.action"),
method
)
Arguments
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
pvs |
if plausible values are not used, this should be |
relatedpvs |
a logical value indicating if |
quiet |
a logical value indicating if progress status should be shown
while estimating models by group. Default is |
summarize |
a logical value indicating if |
setup |
an optional list produced by |
df |
a data frame. |
wt |
a string specifying the name of the column (within |
repwt |
a string indicating the common names for the replicate weights
columns (within |
group |
a string specifying the variable name (within |
exclude |
a vector indicating which groups
(in the same format as |
na.action |
a function which indicates what should happen
when the data contain |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
Value
a list.
Examples
# Less data for shorter example
repdata2 <- repdata[1:1000,]
RW <- repcreate(df = repdata2, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
# Simple regression - weights within df
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = "REPWT", # Common names of replicate weights within df
df = cbind(repdata2,RW), # Data frame
method = "ICILS") # the name of the method aka the study name
# Simple regression - weights as a separate data frame
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
method = "ICILS") # the name of the method aka the study name
# Multiple regression
replm(formula = Math1 ~ 1 + GENDER + Reading1,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with PVs
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading1, # Math1 now is "Math"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with more than one related PV variable
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with more than UNrelated PV variables
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
relatedpvs = FALSE, # Unrelated PVs
method = "ICILS") # the name of the method aka the study name
### Groups ----
# Simple regression - weights within df
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = "REPWT", # Common names of replicate weights within df
df = cbind(repdata2,RW), # Data frame
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Simple regression - weights as a separate data frame
replm(formula = Math1 ~ 1 + GENDER,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression
replm(formula = Math1 ~ 1 + GENDER + Reading1,
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with PVs
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading1, # Math1 now is "Math"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with more than one related PV variable
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
# Multiple regression - with UNrelated PV variables
## Named list, with element names matching formula variables
pvs = list(Math = paste0("Math",1:3),
Reading = paste0("Reading",1:3))
pvs
replm(formula = Math ~ 1 + GENDER + Reading, # Reading1 now is "Reading"
wt = "wt", # Name of total weight column within df
repwt = RW, # Data frame of weights
df = repdata2, # Data frame
pvs = pvs, # Named list
relatedpvs = FALSE, # Unrelated PVs
group = "GROUP",
method = "ICILS") # the name of the method aka the study name
Mean, Variance and Standard Deviation with Replicate Weights
Description
Estimates the mean, variance and standard deviation with replicate weights
for a variable or a group of variables and for one or more
populations. For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
repmean(
x,
PV = FALSE,
setup = NULL,
repwt,
wt,
df,
method,
var = c("unbiased", "ML"),
group = NULL,
by = NULL,
exclude = NULL,
aggregates = c("pooled", "composite"),
zones = NULL
)
Arguments
x |
a string vector specifying variable names (within |
PV |
a logical value indicating if the variables in |
setup |
an optional list produced by |
repwt |
a string indicating the common names for the replicate weights
columns (within |
wt |
a string specifying the name of the column (within |
df |
a data frame. |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
var |
a string indicating the method to use for the variance:
|
group |
a string specifying the variable name (within |
by |
a string specifying a second variable (within |
exclude |
a vector indicating which groups
(in the same format as |
aggregates |
a string vector indicating which aggregates should be
included, options are |
zones |
a string specifying the name of the variable containing the
replicate zones.
Used for calculating the number of zones to be used by variable and group.
If |
Value
a data frame or a list.
Examples
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
# One variable - weights within df
repmean(x = c("item01"),
PV = FALSE,
repwt = "REPWT", wt = "wt", df = cbind(repdata,RW),
method = "ICILS",var = "ML",zones = "jkzones")
# One variable - weights as a separate data frame
repmean(x = c("item01"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones")
# Multiple variables
repmean(x = c("item01","item02","item03"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones")
# One PV variable
repmean(x = paste0("Math",1:5),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones")
### Groups ----
# One variable
repmean(x = c("item01"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
# Multiple variables
repmean(x = c("item01","item02","item03"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
# One PV variable
repmean(x = paste0("Math",1:5),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
### Groups and By ----
# One variable
repmean(x = c("item01"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
by = "GENDER", # results will be separated by GENDER
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
# One PV variable
repmean(x = paste0("Math",1:5),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
by = "GENDER", # results will be separated by GENDER
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
Mean Difference of Independent Samples with Replicate Weights
Description
Estimates the mean difference for a single variable with replicate weights.
For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
repmeandif(x)
Arguments
x |
a data frame produced by |
Value
a data frame or a list.
Examples
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### Groups ----
# One variable
reme <- repmean(x = c("item01"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
repmeandif(reme)
# One PV variable
reme <- repmean(x = paste0("Math",1:5),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
repmeandif(reme)
### Groups and By ----
# One variable
reme <- repmean(x = c("item01"),
PV = FALSE,
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
by = "GENDER", # results will be separated by GENDER
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
repmeandif(reme)
# One PV variable
reme <- repmean(x = paste0("Math",1:5),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RW, wt = "wt", df = repdata,
method = "ICILS",var = "ML",zones = "jkzones",
group = "GROUP",
by = "GENDER", # results will be separated by GENDER
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
repmeandif(reme)
Proportions with Replicate Weights
Description
Estimates proportions using replicate weights
for a variable or a group of plausible values variables and for one or more
populations.
For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
repprop(
x,
categories = NULL,
setup = NULL,
repwt,
wt,
df,
method,
group = NULL,
exclude = NULL
)
Arguments
x |
a string vector specifying variable names (within |
categories |
a vector indicating all possible response categories.
If |
setup |
an optional list produced by |
repwt |
a string indicating the common names for the replicate weights
columns (within |
wt |
a string specifying the name of the column (within |
df |
a data frame. |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
group |
a string specifying the variable name (within |
exclude |
a vector indicating which groups
(in the same format as |
Value
a list.
Examples
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
# One variable - weights within df
repprop(x = c("item01"),
repwt = "REPWT", wt = "wt", df = cbind(repdata,RW),
method = "ICILS")
# One variable - weights weights as a separate data frame
repprop(x = c("item01"),
repwt = RW, wt = "wt", df = repdata,
method = "ICILS")
# Multiple variables - PVs are assumed
repprop(x = c("CatMath1","CatMath2","CatMath3"),
repwt = RW, wt = "wt", df = repdata,
method = "ICILS")
### Groups ----
# One variable - weights within df
repprop(x = c("item01"),
group = "GROUP",
repwt = "REPWT", wt = "wt", df = cbind(repdata,RW),
method = "ICILS")
# One variable - weights weights as a separate data frame
repprop(x = c("item01"),
group = "GROUP",
repwt = RW, wt = "wt", df = repdata,
method = "ICILS")
# Multiple variables - PVs are assumed
repprop(x = c("CatMath1","CatMath2","CatMath3"),
group = "GROUP",
repwt = RW, wt = "wt", df = repdata,
method = "ICILS")
# Multiple variables - excluding one group
repprop(x = c("CatMath1","CatMath2","CatMath3"),
group = "GROUP",
exclude = "GR2",
repwt = RW, wt = "wt", df = repdata,
method = "ICILS")
Quantiles with Replicate Weights
Description
Estimates quantiles with replicate weights
for a variable or a group of variables and for one or more
populations.
For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
repquant(
x,
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = FALSE,
setup = NULL,
repwt,
wt,
df,
method,
group = NULL,
by = NULL,
exclude = NULL
)
Arguments
x |
a string vector specifying variable names (within |
qtl |
a numeric vector indicating the desired quantiles (between 0 and 1). |
PV |
a logical value indicating if the variables in |
setup |
an optional list produced by |
repwt |
a string indicating the common names for the replicate weights
columns (within |
wt |
a string specifying the name of the column (within |
df |
a data frame. |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
group |
a string specifying the variable name (within |
by |
a string specifying a second variable (within |
exclude |
a vector indicating which groups
(in the same format as |
Value
a data frame or a list.
Examples
RWT <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
# One variable - weights within df
repquant(x = c("item01"),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = FALSE,
repwt = "REPWT", wt = "wt", df = cbind(repdata,RWT),
method = "ICILS")
# One variable - weights as a separate data frame
repquant(x = c("item01"),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = FALSE,
repwt = RWT, wt = "wt", df = repdata,
method = "ICILS")
# One PV variable
repquant(x = paste0("Math",1:5),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RWT, wt = "wt", df = repdata,
method = "ICILS")
### Groups ----
# One variable
repquant(x = c("item01"),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = FALSE,
repwt = RWT, wt = "wt", df = repdata,
method = "ICILS",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
# One PV variable
repquant(x = paste0("Math",1:5),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RWT, wt = "wt", df = repdata,
method = "ICILS",
group = "GROUP",
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
### Groups and By ----
# One variable
repquant(x = c("item01"),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = FALSE,
repwt = RWT, wt = "wt", df = repdata,
method = "ICILS",
group = "GROUP",
by = "GENDER", # results will be separated by GENDER
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
# One PV variable
repquant(x = paste0("Math",1:5),
qtl = c(0.05, 0.25, 0.75, 0.95),
PV = TRUE, # if set to TRUE, PVs will be treated as separate variables
repwt = RWT, wt = "wt", df = repdata,
method = "ICILS",
group = "GROUP",
by = "GENDER", # results will be separated by GENDER
exclude = "GR2") # GR2 will not be used for Pooled nor Composite
Correlations with Replicate Weights
Description
Estimates correlation coefficients using replicate weights.
For a detailed explanation on how the standard errors are estimated
see repse
.
Usage
reprho(
x = NULL,
pv = NULL,
pv2 = NULL,
relatedpvs = TRUE,
setup = NULL,
repwt,
wt,
df,
rho = c("pearson", "spearman", "polychoric"),
method,
group = NULL,
exclude = NULL,
aggregates = c("pooled", "composite")
)
Arguments
x |
a string vector specifying variable names (within |
pv |
a string vector indicating the variable names for all plausible values
of a construct. If not |
pv2 |
a string vector indicating the variable names for all plausible values
of a second construct (distinct from |
relatedpvs |
a logical value indicating if |
setup |
an optional list produced by |
repwt |
a string indicating the common names for the replicate weights
columns (within |
wt |
a string specifying the name of the column (within |
df |
a data frame. |
rho |
a string indicating the correlation coefficient to be computed:
|
method |
a string indicating the name of the replication method.
Available options are:
Note that |
group |
a string specifying the variable name (within |
exclude |
a vector indicating which groups (in the same format as |
aggregates |
a string vector indicating which aggregates should be
included, options are |
Value
a data frame.
Examples
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
# Non PVs
reprho(x = c("GENDER",paste0("Math",1:3)),
pv = NULL,
pv2 = NULL,
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
method = "ICILS")
# X var and PVs
reprho(x = c("GENDER",paste0("Math",1:3)),
pv = paste0("Reading",1:5),
pv2 = NULL,
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
method = "ICILS")
# PVs and PVs (related)
reprho(x = NULL,
pv = paste0("Math",1:5),
pv2 = paste0("Reading",1:5),
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
method = "ICILS")
# PVs and PVs (UNrelated)
reprho(x = NULL,
pv = paste0("Math",1:5),
pv2 = paste0("Reading",1:5),
relatedpvs = FALSE,
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
method = "ICILS")
### Groups ----
# Non PVs
reprho(x = c("GENDER",paste0("Math",1:3)),
pv = NULL,
pv2 = NULL,
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
group = "GROUP",
method = "ICILS")
# X var and PVs
reprho(x = c("GENDER",paste0("Math",1:3)),
pv = paste0("Reading",1:5),
pv2 = NULL,
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
group = "GROUP",
method = "ICILS")
# PVs and PVs (related)
reprho(x = NULL,
pv = paste0("Math",1:5),
pv2 = paste0("Reading",1:5),
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
group = "GROUP",
method = "ICILS")
# PVs and PVs (UNrelated)
reprho(x = NULL,
pv = paste0("Math",1:5),
pv2 = paste0("Reading",1:5),
relatedpvs = FALSE,
rho = "pearson",
repwt = RW,
wt = "wt",
df = repdata,
group = "GROUP",
method = "ICILS")
Standard Error for Estimates with Replicate Weights and Plausible Values
Description
Calculates the standard error given a vector or list of previous estimations.
Usage
repse(er, e0, setup = NULL, method)
repsecomp(se)
pvse(PVse, PVe0, df = FALSE)
Arguments
er |
a vector or a list containing any statistic of interest
(e.g., percent, mean, variance, regression coefficient).
If it is a vector or list of |
e0 |
a numeric vector or a vector containing any statistic of interest
(e.g., percent, mean, variance, regression coefficient), computed using
total weights. For scenarios without plausible values,
|
setup |
an optional list produced by |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
se |
a numeric vector with standard errors,
used by |
PVse |
a numeric vector containing the standard errors of the estimates of each plausible value. |
PVe0 |
a numeric vector containing the point estimates of each plausible value. |
df |
a logical value indicating if degrees should be calculated. |
Details
The standard errors are calculated using a modifier m
, for JK2-full: m = 0.5
;
for JK2-half: m = 1
; and for FAY-0.5:
\frac{1}{R(1-0.5)^2}
. Depending on the statistic, one of the following
formulas is used.
The standard error not involving plausible values is calculated by:
\sqrt{m\times \sum_{r=1}^{R}(\varepsilon_r-\varepsilon_0)^2}.
The standard error involving plausibles values and replicate weights is calculated by:
\sqrt{\left[ \sum_{p=1}^{P} \left( m\times \sum_{r=1}^{R}(\varepsilon_{rp}-\varepsilon_{0p})^2 \right) \dfrac{1}{P}\right]+ \left[ \left(1+ \dfrac{1}{P} \right) \dfrac{\sum_{p=1}^{P} (\varepsilon_{0p}-\overline{\varepsilon}_{0p})^{2}}{P-1} \right]}.
The standard error involving plausibles values without replicate weights is calculated by:
\sqrt{ \dfrac{\sum_{p=1}^{P} SE^2_{\varepsilon_{0P}}}{P}+ \left[ \left(1+ \dfrac{1}{P} \right) \dfrac{\sum_{p=1}^{P} (\varepsilon_{0p}-\overline{\varepsilon}_{0p})^{2}}{P-1} \right]}.
The standard error of the difference of
two statistics (a
and b
) from independent samples is calculated by:
\sqrt{SE_a^{2}+SE_b^{2}}.
The standard error of the difference of
two statistics (a
and b
) from dependent samples
not involving plausible values
is calculated by:
\sqrt{m\times \sum_{r=1}^R((a_r-b_r)-(a_0-b_0))^2}.
The standard error of the difference of
two statistics (a
and b
) from dependent samples
involving plausible values
is calculated by:
\sqrt{\left[ \sum_{p=1}^{P} \left( m\times \sum_{r=1}^{R}((a_{rp}-b_{rp})-(a_{0p}-b_{0p}))^2 \right) \dfrac{1}{P}\right]+ \left[ \left(1+ \dfrac{1}{P} \right) \dfrac{\sum_{p=1}^{P} \left((a_{0p}-b_{0p})- ( \overline{a}_{0p}-\overline{b}_{0p}) \right)^{2}}{P-1} \right]}.
The standard error of a composite estimate is calculated by:
\sqrt{\dfrac{\sum_{c=1}^CSE^2_{\varepsilon_c}}{C^{2}}}.
The standard error of the difference between an element (a
) of the composite
and the composite is calculated by:
\sqrt{\dfrac{\sum_{c=1}^CSE^2_{\varepsilon_c}}{C^{2}}+\left(\dfrac{(C-1)^2-1}{C^2}\right)SE^2_a}.
Where
\varepsilon
represents a statistic of interest,
the subindex 0
indicates an estimate using the total weights,
r
indicates a replicate from a total of R
,
p
indicates a plausible value from a total of P
,
and c
indicates an element in a composite estimate from value a total of C
.
Value
the standard error.
Examples
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
# Non-PVs ----
## Mean with total weights
E0 <- stats::weighted.mean(x = repdata$item01, w = repdata$wt, na.rm = TRUE)
E0
## Means by replication
ER <- as.vector(apply(RW,2,function(i){
stats::weighted.mean(x = repdata$item01, w = i, na.rm = TRUE)
}))
ER
## Standard error by hand
repse(er = ER, e0 = E0, method = "ICILS")
## Standard error with repmean()
repmean(x = "item01",wt = "wt",repwt = RW,df = repdata, method = "ICILS")
# PVs ----
## Mean with total weights
E0 <- sapply(1:5,function(i){
stats::weighted.mean(x = repdata[,paste0("Math",i)], w = repdata$wt,
na.rm = TRUE)
})
E0
## Means by replication
ER <- lapply(1:5, function(j){
as.vector(apply(RW,2,function(i){
stats::weighted.mean(x = repdata[,paste0("Math",j)], w = i, na.rm = TRUE)
}))
})
ER
## Standard error by hand
repse(er = ER, e0 = E0, method = "ICILS")
## Standard error with repmean()
repmean(x = paste0("Math",1:5),wt = "wt",repwt = RW,df = repdata, method = "ICILS",PV = TRUE)
Setup for Analysis with Replicate Weights
Description
Creates a list with common arguments used for analysis with replicate weights.
Usage
repsetup(repwt, wt, df, method, group = NULL, exclude = NULL)
repsetupILSA(study, year, repwt, df, group = NULL, exclude = NULL)
Arguments
repwt |
a string indicating the common names for the replicate weights
columns (within |
wt |
a string specifying the name of the column (within |
df |
a data frame. |
method |
a string indicating the name of the replication method.
Available options are:
Note that |
group |
a string specifying the variable name (within |
exclude |
a vector indicating which groups
(in the same format as |
study |
a string indicating the study name. For checking available studies use
|
year |
a numeric value indicating the study year. For checking available
years use
|
Value
a list to be used in other functions.
Examples
# Creation of replicate weights
RW <- repcreate(df = repdata, # the data frame with all the information
wt = "wt", # the total weights column name
jkzone = "jkzones", # the jkzones column name
jkrep = "jkrep", # the jkreps column name
repwtname = "REPWT", # the desired name for the rep weights
reps = 50, # the number of replications
method = "ICILS") # the name of the method aka the study name
### No groups ----
stp1 <- repsetup(repwt = RW, wt = "wt", df = repdata, method = "ICILS")
stp1
### Groups ----
stp2 <- repsetup(repwt = RW, wt = "wt", df = repdata, method = "ICILS",
group = "GROUP", exclude = "GR2")
stp2
### repmean ----
repmean(x = "Math1",setup = stp1)
repmean(x = "Math1",setup = stp2)