repTable.Rd
Compute frequency tables for categorical variables (e.g. factors: dichotomous or polytomous) in complex
cluster designs. Estimation of standard errors optionally takes the clustered structure and multiple imputed
variables into account. To date, Jackknife-1 (JK1), Jackknife-2 (JK2) and Balanced repeated replicate (BRR) methods are
implemented to account for clustered designs. Procedures of Rubin (1987) and Rubin (2003) are implemented to account for
multiple imputed data and nested imputed data, if necessary. Conceptually, the function combines replication and imputation
methods. Technically, this is a wrapper for the svymean
function of the survey
package.
repTable(datL, ID, wgt = NULL, type = c("none", "JK2", "JK1", "BRR", "Fay"), PSU = NULL,
repInd = NULL, jkfac=NULL, repWgt = NULL, nest=NULL, imp=NULL, groups = NULL,
group.splits = length(groups), group.differences.by = NULL,
cross.differences = FALSE, crossDiffSE = c("wec", "rep","old"),
nBoot = 100, chiSquare = FALSE, correct = TRUE, group.delimiter = "_",
trend = NULL, linkErr = NULL, dependent, separate.missing.indicator = FALSE,
na.rm=FALSE, expected.values = NULL, doCheck = TRUE, forceTable = FALSE,
engine = c("survey", "BIFIEsurvey"), scale = 1, rscales = 1, mse=TRUE,
rho=NULL, verbose = TRUE, progress = TRUE, nCores=NULL )
Data frame in the long format (i.e. each line represents one ID unit in one imputation of one nest) containing all variables for analysis.
Variable name or column number of student identifier (ID) variable. ID variable must not contain any missing values.
Optional: Variable name or column number of weighting variable. If no weighting variable is specified, all cases will be equally weighted.
Defines the replication method for cluster replicates which is to be applied. Depending on type
, additional
arguments must be specified (e.g., PSU
and/or repInd
or repWgt
).
Variable name or column number of variable indicating the primary sampling unit (PSU). When a jackknife procedure is applied,
the PSU is the jackknife zone variable. If NULL
, no cluster structure is assumed and
standard errors are computed according to a random sample.
Variable name or column number of variable indicating replicate ID. In a jackknife procedure, this is the jackknife replicate
variable. If NULL
, no cluster structure is assumed and standard errors are computed according to a random sample.
Only applies if engine = "BIFIEsurvey"
. Argument is passed to BIFIE.data.jack
and specifies
the factor for multiplying jackknife replicate weights.
Normally, replicate weights are created by repTable
directly from PSU
and repInd
variables. Alternatively,
if replicate weights are included in the data.frame, specify the variable names or column number in the repWgt
argument.
Optional: name or column number of the nesting variable. Only applies in nested multiple imputed data sets.
Optional: name or column number of the imputation variable. Only applies in multiple imputed data sets.
Optional: vector of names or column numbers of one or more grouping variables.
Optional: If groups are defined, group.splits
optionally specifies whether analysis should be done also
in the whole group or overlying groups. See examples for more details.
Optional: Specifies one grouping variable for which a chi-square test should be applied.
The corresponding variable must be included in the groups
statement. If specified, the
distribution of the dependent variable is compared between the groups. See examples for
further details.
Either a list of vectors, specifying the pairs of levels for which cross-level differences should be computed.
Alternatively, if TRUE, cross-level differences for all pairs of levels are computed. If FALSE, no cross-level
differences are computed. (see examples 2a, 3, and 4 in the help file of the repMean
function)
Method for standard error estimation for cross level differences, where groups are dependent.
wec
uses weighted effect coding, rep
uses replication methods (bootstrap or jackknife) to
estimate the standard error between the total mean and group-specific means. old
does not account for dependent
groups and treat the groups as if they were independent from each other.
Without replicates (i.e., for completely random samples), the rep
method for standard error estimation for
cross level differences needs a bootstrap. nBoot
therefore specifies the number of bootstrap samples.
This argument is only necessary, if crossDiffSE = "rep"
and none of the replicate methods
(JK1, JK2, or BRR) is applied. Otherwise, nBoot
will be ignored.
Logical. Applies only if group.differences.by
was specified. Defines whether
group differences should be represented in a chi square test or in (mean) differences of each
group's relative frequency. Note: To date, chi square test is not available for engine = "BIFIEsurvey"
.
Logical. Applies only if 'group.differences.by' is requested without cluster replicates. A logical indicating whether to apply continuity correction when computing the test statistic for 2 by 2 tables. See help page of 'chisq.test' for further details.
Character string which separates the group names in the output frame.
Optional: name or column number of the trend variable which contains the measurement time of the survey.
Note: Levels of all grouping variables must be equal in all 'sub populations' partitioned by the discrete trend variable.
repTable
computes differences for all pairwise contrasts defined by trend variable levels. or three measurement
occasions, i.e. 2010, 2015, and 2020, contrasts (i.e. trends) are computed for 2010 vs. 2015, 2010 vs. 2020, and
2015 vs. 2020.
Optional: Either the name or column number of the linking error variable. If NULL
, a linking error of 0 will be assumed in trend estimation.
Alternatively, linking errors may be
given as data.frame
with following specifications: Two columns, named trendLevel1
and trendLevel2
which contain the
levels of the trend variable. The contrasts between both values indicates which trend is meant. For only two measurement occasions, i.e.
2010 and 2015, trendLevel1
should be 2010
, and trendLevel2
should be 2015
. For three measurement occasions,
i.e. 2010, 2015, and 2020, additional lines are necessary where trendLevel1
should be 2010
, and trendLevel2
should be
2020
, to mark the contrast between 2010 and 2020, and further additional lines are necessary where trendLevel1
should be
2015
, and trendLevel2
should be 2020
. The column depVar
must include the name of the dependent variable. This
string must correspond to the name of the dependent variable in the data. The column parameter
indicates the parameter the linking
error belongs to. Column linkingError
includes the linking error value. Providing linking error in a data.frame is necessary for
more than two measurement occasions. See the fourth example below for further details.
Variable name or column number of the dependent variable.
Logical. Should frequencies of missings in dependent variable be integrated? Note: That is only useful if missing occur as NA
. If the dependent variable
is coded as character, for example 'male', 'female', 'missing'
, separate missing indicator is not necessary.
Logical: Should cases with missing values be dropped?
Optional. A vector of values expected in dependent variable. Recommend to left this argument empty.
Logical: Check the data for consistency before analysis? If TRUE
groups with insufficient data are excluded from
analysis to prevent subsequent functions from crashing.
Logical: Function decides internally whether the table or the mean function of survey
is called.
If the mean function is called, the polytomous dependent variable is converted to dichotomous indicator
variables. If mean is called, group differences for each category of the polytomous dependent variable
can be computed. If table is called, a chi square statistic may be computed. The argument allows to
force the function either to call mean or table.
Which package should be used for estimation?
scaling constant for variance, for details, see help page of svrepdesign
from the survey
package
scaling constant for variance, for details, see help page of svrepdesign
from the survey
package
Logical: If TRUE
, compute variances based on sum of squares around the point estimate, rather than the mean of the replicates.
See help page of svrepdesign
from the survey
package for further details.
Shrinkage factor for weights in Fay's method. If engine = "survey"
, argument is passed to the rho
argument of
the svrepdesign
function from the survey
package. See the corresponding help page for further
details. If engine = "BIFIEsurvey"
, argument is passed to the fayfac
argument of the
BIFIE.data.jack
function from the BIFIEsurvey
package. See the
corresponding help page for further details. For convenience, if rho = NULL
(the default)
and engine = "BIFIEsurvey"
and type = "JK1"
, BIFIE.data.jack
is called with jktype="JK_GROUP"
and fayfac = rho
, where \(\rho = (N_{cluster} - 1) \times N_{cluster}^{-1}\)
Logical: Show analysis information on console?
Logical: Show progress bar on console?
integer (default: NULL), number of cores to use for parallel processing, if engine = "survey"
. If NULL
,
single core processing is used.
Function first creates replicate weights based on PSU and repInd variables according to JK2 procedure
implemented in WesVar. According to multiple imputed data sets, a workbook with several analyses is created.
The function afterwards serves as a wrapper for svymean
called by svyby
implemented in the survey
package.
Relative frequencies of the categories of the dependent variable are computed by the means of the dichotomous indicators
(e.g. dummy variables) of each category. The results of the several analyses are then pooled according to Rubin's rule,
which is adapted for nested imputations if the dependent
argument implies a nested structure.
A list of data frames in the long format. The output can be summarized using the report
function.
The first element of the list is a list with either one (no trend analyses) or two (trend analyses)
data frames with at least six columns each. For each subpopulation denoted by the groups
statement, each
dependent variable, each parameter (i.e., the values of the corresponding categories of the dependent variable)
and each coefficient (i.e., the estimate and the corresponding standard error) the corresponding value is given.
Denotes the group an analysis belongs to. If no groups were specified and/or analysis for the whole sample were requested, the value of ‘group’ is ‘wholeGroup’.
Denotes the name of the dependent variable in the analysis.
Denotes the mode of the analysis. For example, if a JK2 analysis without sampling weights was conducted, ‘modus’ takes the value ‘jk2.unweighted’. If a analysis without any replicates but with sampling weights was conducted, ‘modus’ takes the value ‘weighted’.
Denotes the parameter of the regression model for which the corresponding value is given further. For frequency tables, this is the value of the category of the dependent variable which relative frequency is given further.
Denotes the coefficient for which the corresponding value is given further. Takes the values ‘est’ (estimate) and ‘se’ (standard error of the estimate).
The value of the parameter, i.e. the relative frequency or its standard error.
If groups were specified, further columns which are denoted by the group names are added to the data frame.
Rubin, D.B. (2003): Nested multiple imputation of NMES via partially incompatible MCMC. Statistica Neerlandica 57, 1, 3–18.
data(lsa)
### Example 1: only means, SD and variances for each country
### subsetting: We only consider domain 'reading'
rd <- lsa[which(lsa[,"domain"] == "reading"),]
### We only consider the first "nest".
rdN1 <- rd[which(rd[,"nest"] == 1),]
### First, we only consider year 2010
rdN1y10<- rdN1[which(rdN1[,"year"] == 2010),]
# \donttest{
### First example: Computes frequencies of polytomous competence levels (1, 2, 3, 4, 5)
### conditionally on country, using a chi-square test to decide whether the distribution
### varies between countries (it's an overall test, i.e. with three groups, df1=8).
freq.tab1 <- repTable(datL = rdN1y10, ID = "idstud", wgt = "wgt", imp="imp",
type = "JK2", PSU = "jkzone", repInd = "jkrep", groups = "country",
group.differences.by = "country", dependent = "comp", chiSquare = TRUE)
#> 1 analyse(s) overall according to: 'group.splits = 1'.
#> Assume unnested structure with 3 imputations.
#> Create 92 replicate weights according to JK2 procedure.
#>
res1 <- report(freq.tab1, add = list ( domain = "reading" ))
#> Chi sqare test results cannot be transferred to old report() structure and will be ignored. Please use report2() instead.
### Second example: Computes frequencies of polytomous competence levels (1, 2, 3, 4, 5)
### conditionally on country. Now we test whether the frequency of each single category
### differs between pairs of countries (it's not an overall test ... repTable now
### calls repMean internally, using dummy variables)
freq.tab2 <- repTable(datL = rdN1y10, ID = "idstud", wgt = "wgt", imp="imp",
type = "JK2", PSU = "jkzone", repInd = "jkrep", groups = "country",
group.differences.by = "country", dependent = "comp", chiSquare = FALSE)
#> 1 analyse(s) overall according to: 'group.splits = 1'.
#> Assume unnested structure with 3 imputations.
#> Create 92 replicate weights according to JK2 procedure.
#>
#> 1 analyse(s) overall according to: 'group.splits = 1'.
#> Assume unnested structure with 3 imputations.
#> Create 92 replicate weights according to JK2 procedure.
#>
#> 1 analyse(s) overall according to: 'group.splits = 1'.
#> Assume unnested structure with 3 imputations.
#> Create 92 replicate weights according to JK2 procedure.
#>
#> 1 analyse(s) overall according to: 'group.splits = 1'.
#> Assume unnested structure with 3 imputations.
#> Create 92 replicate weights according to JK2 procedure.
#>
#> 1 analyse(s) overall according to: 'group.splits = 1'.
#> Assume unnested structure with 3 imputations.
#> Create 92 replicate weights according to JK2 procedure.
#>
res2 <- report(freq.tab2, add = list ( domain = "reading" ))
### Third example: trend estimation and nested imputation and 'by' loop
### (to date, only crossDiffSE = "old" works)
freq.tab3 <- by ( data = lsa, INDICES = lsa[,"domain"], FUN = function (subdat) {
repTable(datL = subdat, ID = "idstud", wgt = "wgt", imp="imp",
nest = "nest", type = "JK2", PSU = "jkzone", repInd = "jkrep",
groups = "country", group.differences.by = "country",
group.splits = 0:1, cross.differences = TRUE, crossDiffSE = "old",
dependent = "comp", chiSquare = FALSE, trend = "year",
linkErr = "leComp") })
#> To date, only method 'old' is applicable for cross level differences in frequency tables.
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#> To date, only method 'old' is applicable for cross level differences in frequency tables.
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 92 replicate weights according to JK2 procedure.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#> Create 73 replicate weights according to JK2 procedure.
#>
res3 <- do.call("rbind", lapply(names(freq.tab3), FUN = function (domain) {
report(freq.tab3[[domain]], add = list ( domain = domain )) }))
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryA'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryB'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryC'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryA'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryB'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryC'.
#> Warning: Found 7 missing linking errors for dependent variable 'comp' and parameter(s) 'NcasesValid'. Assume linking error of 0 for these cases.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryA'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryB'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryC'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryA'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryB'.
#> Warning: No standard error for parameter 'NcasesValid'. Cannot compute standard errors and p value for cross-level difference between 'wholeGroup' and 'countryC'.
#> Warning: Found 7 missing linking errors for dependent variable 'comp' and parameter(s) 'NcasesValid'. Assume linking error of 0 for these cases.
### Fourth example: similar to example 3. trend estimation using a linking
### error data.frame
linkErrs <- data.frame ( trendLevel1 = 2010, trendLevel2 = 2015, depVar = "comp",
unique(lsa[,c("domain", "comp", "leComp")]), stringsAsFactors = FALSE)
colnames(linkErrs) <- car::recode(colnames(linkErrs),
"'comp'='parameter'; 'leComp'='linkingError'")
freq.tab4 <- by ( data = lsa, INDICES = lsa[,"domain"], FUN = function (subdat) {
repTable(datL = subdat, ID = "idstud", wgt = "wgt", type="none",
imp="imp", nest = "nest", groups = "country",
group.differences.by = "country", group.splits = 0:1,
cross.differences = FALSE, dependent = "comp", chiSquare = FALSE,
trend = "year",
linkErr = linkErrs[which(linkErrs[,"domain"] == subdat[1,"domain"]),])
})
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2010'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
#>
#> Trend group: '2015'
#> 2 analyse(s) overall according to: 'group.splits = 0 1'.
#>
#> analysis.number hierarchy.level groups.divided.by group.differences.by
#> 1 0 <NA>
#> 2 1 country country
#>
#> Assume nested structure with 2 nests and 3 imputations in each nest. This will result in 2 x 3 = 6 imputation replicates.
#>
res4 <- do.call("rbind", lapply(names(freq.tab4), FUN = function (domain) {
report(freq.tab4[[domain]], add = list ( domain = domain )) }))
#> Warning: No linking errors for parameters 'Ncases', 'NcasesValid'. Linking errors for these parameters will be defaulted to 0.
#> Warning: Found 4 missing linking errors for dependent variable 'comp' and parameter(s) 'NcasesValid'. Assume linking error of 0 for these cases.
#> Warning: No linking errors for parameters 'Ncases', 'NcasesValid'. Linking errors for these parameters will be defaulted to 0.
#> Warning: Found 4 missing linking errors for dependent variable 'comp' and parameter(s) 'NcasesValid'. Assume linking error of 0 for these cases.
### Fifth example: minimal example for three measurement occasions
### borrow data from the eatGADS package
trenddat1 <- system.file("extdata", "trend_gads_2010.db", package = "eatGADS")
trenddat2 <- system.file("extdata", "trend_gads_2015.db", package = "eatGADS")
trenddat3 <- system.file("extdata", "trend_gads_2020.db", package = "eatGADS")
trenddat <- eatGADS::getTrendGADS(filePaths = c(trenddat1, trenddat2, trenddat3),
years = c(2010, 2015, 2020), fast=FALSE)
#> ----- Loading GADS 2010 -----
#> ----- Loading GADS 2015 -----
#> ----- Loading GADS 2020 -----
dat <- eatGADS::extractData(trenddat)
### use template linking Error Object
load(system.file("extdata", "linking_error.rda", package = "eatRep"))
### check consistency of data and linking error object
check1 <- checkLEs(c(trenddat1, trenddat2, trenddat3), lErr)
#> The following variables have linking errors but are not variables in data base 1: 'value', 'valueTransfBista'
#> The following variables have linking errors but are not variables in data base 2: 'value', 'valueTransfBista'
#> The following variables have linking errors but are not variables in data base 3: 'value', 'valueTransfBista'
### Analysis for reading comprehension
freq.tab5 <- repTable(datL = dat[which(dat[,"dimension"] == "reading"),],
ID = "idstud", type="none", imp="imp", dependent = "traitLevel",
chiSquare = FALSE, trend = "year",
linkErr = lErr[which(lErr[,"domain"] == "reading"),])
#> 'idVar' is unique per row in 'GADSdat' and checking for uniqueness is obsolete.
#> 'idVar' is unique per row in 'GADSdat' and checking for uniqueness is obsolete.
#>
#> Trend group: '2010'
#> 1 analyse(s) overall according to: 'group.splits = 0'.
#> Assume unnested structure with 3 imputations.
#>
#>
#> Trend group: '2015'
#> 1 analyse(s) overall according to: 'group.splits = 0'.
#> Assume unnested structure with 3 imputations.
#>
#>
#> Trend group: '2020'
#> 1 analyse(s) overall according to: 'group.splits = 0'.
#> Assume unnested structure with 3 imputations.
#>
res5 <- report(freq.tab5, add = list ( domain = "reading" ))
#> Warning: No linking errors for parameters 'Ncases'. Linking errors for these parameters will be defaulted to 0.
#>
#> Following 3 units in trend group '2010' without counterpart in trend group '2020'.
#>
#> group depVar comparison parameter coefficient value
#> 10 wholeGroup traitLevel none 4 est 0.1333333
#> 11 wholeGroup traitLevel none 4 se 0.1305260
#> 12 wholeGroup traitLevel none 4 p 0.3070139
#>
#> No '2010.vs.2020' trends will be computed.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'y' not included in data set 'x'.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'x' not included in data set 'y'.
#> 1 of 3 unit(s) of merging variable 'coefficient' from data set 'y' not included in data set 'x'.
#> 12 of 24 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'y' not included in data set 'x'.
#> 2 of 14 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'x' not included in data set 'y'.
#>
#> Following 3 units in trend group '2015' without counterpart in trend group '2020'.
#>
#> group depVar comparison parameter coefficient value
#> 10 wholeGroup traitLevel none 4 est 0.3333333
#> 11 wholeGroup traitLevel none 4 se 0.1699673
#> 12 wholeGroup traitLevel none 4 p 0.0498602
#>
#> No '2015.vs.2020' trends will be computed.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'y' not included in data set 'x'.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'x' not included in data set 'y'.
#> 1 of 3 unit(s) of merging variable 'coefficient' from data set 'y' not included in data set 'x'.
#> 12 of 24 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'y' not included in data set 'x'.
#> 2 of 14 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'x' not included in data set 'y'.
res5A <- report2(freq.tab5, add = list ( domain = "reading" ))
#> Warning: No linking errors for parameters 'Ncases'. Linking errors for these parameters will be defaulted to 0.
#>
#> Following 3 units in trend group '2010' without counterpart in trend group '2020'.
#>
#> group depVar comparison parameter coefficient value
#> 10 wholeGroup traitLevel none 4 est 0.1333333
#> 11 wholeGroup traitLevel none 4 se 0.1305260
#> 12 wholeGroup traitLevel none 4 p 0.3070139
#>
#> No '2010.vs.2020' trends will be computed.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'y' not included in data set 'x'.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'x' not included in data set 'y'.
#> 1 of 3 unit(s) of merging variable 'coefficient' from data set 'y' not included in data set 'x'.
#> 12 of 24 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'y' not included in data set 'x'.
#> 2 of 14 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'x' not included in data set 'y'.
#>
#> Following 3 units in trend group '2015' without counterpart in trend group '2020'.
#>
#> group depVar comparison parameter coefficient value
#> 10 wholeGroup traitLevel none 4 est 0.3333333
#> 11 wholeGroup traitLevel none 4 se 0.1699673
#> 12 wholeGroup traitLevel none 4 p 0.0498602
#>
#> No '2015.vs.2020' trends will be computed.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'y' not included in data set 'x'.
#> 1 of 4 unit(s) of merging variable 'parameter' from data set 'x' not included in data set 'y'.
#> 1 of 3 unit(s) of merging variable 'coefficient' from data set 'y' not included in data set 'x'.
#> 12 of 24 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'y' not included in data set 'x'.
#> 2 of 14 unit(s) of merging variable combination 'comparison'+'parameter'+'coefficient'+'year' from data set 'x' not included in data set 'y'.
# }