lsa.crosstabs {RALSA} | R Documentation |
Compute crosstabulations and design corrected chi-square statistics
Description
lsa.crosstabs
computes two-way tables and estimates the Rao-Scott first- and second-order adjusted chi-square.
Usage
lsa.crosstabs(
data.file,
data.object,
split.vars,
bckg.row.var,
bckg.col.var,
expected.cnts = TRUE,
row.pcts = FALSE,
column.pcts = FALSE,
total.pcts = FALSE,
weight.var,
include.missing = FALSE,
shortcut = FALSE,
graphs = FALSE,
graph.row.label = NULL,
graph.col.label = NULL,
save.output = TRUE,
output.file,
open.output = TRUE
)
Arguments
data.file |
A file containing |
data.object |
An object in the memory containing |
split.vars |
Categorical variable(s) to split the results by. If no split variables are provided, the results will be for the overall countries' populations. If one or more variables are provided, the results will be split by all but the last variable and the percentages of respondents will be computed by the unique values of the last splitting variable. |
bckg.row.var |
Name of the categorical background row variable. The results will be computed by all groups specified by the splitting variables. See details. |
bckg.col.var |
Name of the categorical background column variable. The results will be computed by all groups specified by the splitting variables. See details. |
expected.cnts |
Logical, shall the expected counts be computed as well? The default
( |
row.pcts |
Logical, shall row percentages be computed? The default ( |
column.pcts |
Logical, shall column percentages be computed? The default ( |
total.pcts |
Logical, shall percentages of total be computed? The default
( |
weight.var |
The name of the variable containing the weights. If no name of a weight variable is provided, the function will automatically select the default weight variable for the provided data, depending on the respondent type. |
include.missing |
Logical, shall the missing values of the splitting variables be included
as categories to split by and all statistics produced for them? The
default ( |
shortcut |
Logical, shall the "shortcut" method for IEA TIMSS, TIMSS Advanced,
TIMSS Numeracy, eTIMSS, PIRLS, ePIRLS, PIRLS Literacy and RLII be
applied? The default ( |
graphs |
Logical, shall graphs be produced? Default is |
graph.row.label |
String, custom label for the row variable in graphs. Ignored if
|
graph.col.label |
String, custom label for the column variable in graphs. Ignored if
|
save.output |
Logical, shall the output be saved in MS Excel file (default) or not (printed to the console or assigned to an object). |
output.file |
If |
open.output |
Logical, shall the output be open after it has been written? The default
( |
Details
The function computes two-way tables between two categorical variables and estimates the Rao-Scott first- and second-order design correction of the chi-square statistics. All statistics are computed within the groups specified by the last splitting variable. If no splitting variables are added, the results will be computed only by country.
Either data.file
or data.object
shall be provided as source of data. If both of them are provided, the function will stop with an error message.
Only two (row and column) categorical variables can be provided. The function always computes the observed counts. If requested, the expected counts, row percentages, column percentages and total percentages can be computed as well.
If include.missing = FALSE
(default), all cases with missing values on the splitting variables will be removed and only cases with valid values will be retained in the statistics. Note that the data from the studies can be exported in two different ways: (1) setting all user-defined missing values to NA
; and (2) importing all user-defined missing values as valid ones and adding their codes in an additional attribute to each variable. If the include.missing
is set to FALSE
(default) and the data used is exported using option (2), the output will remove all values from the variable matching the values in its missings
attribute. Otherwise, it will include them as valid values and compute statistics for them.
The shortcut
argument is valid only for TIMSS, eTIMSS, TIMSS Advanced, TIMSS Numeracy, PIRLS, ePIRLS, PIRLS Literacy and RLII. Previously, in computing the standard errors, these studies were using 75 replicates because one of the schools in the 75 JK zones had its weights doubled and the other one has been taken out. Since TIMSS 2015 and PIRLS 2016 the studies use 150 replicates and in each JK zone once a school has its weights doubled and once taken out, i.e. the computations are done twice for each zone. For more details see Foy & LaRoche (2016) and Foy & LaRoche (2017).
If graphs = TRUE
, the function will produce graphs, heatmaps of counts per combination of bckg.row.var
and bckg.col.var
category (population estimates) per group defined by the split.vars
will be produced. All plots are produced per country. If no split.vars
at the end there will be a heatmap for all countries together. By default the row and column variable names are used for labeling the axes of the heatmaps, unless graph.row.label
and/or graph.col.label
arguments are supplied. These two arguments accept strings of length 1 which will be used to label the axes.
The function also computes chi-square statistics with Rao-Scott first- and second-order design corrections because of the clustering in complex survey designs. For more details, see Rao & Scott (1984, 1987) and Skinner (2019).
Value
If save.output = FALSE
, a list containing the estimates and analysis information. If graphs = TRUE
, the plots will be added to the list of estimates.
If save.output = TRUE
(default), an MS Excel (.xlsx
) file (which can be opened in any spreadsheet program), as specified with the full path in the output.file
. If the argument is missing, an Excel file with the generic file name "Analysis.xlsx" will be saved in the working directory (getwd()
). The workbook contains four spreadsheets. The first one ("Estimates") contains a table with the results by country and the final part of the table contains averaged results from all countries' statistics. The following columns can be found in the table, depending on the specification of the analysis:
-
<
Country ID>
- a column containing the names of the countries in the file for which statistics are computed. The exact column header will depend on the country identifier used in the particular study. -
<
Split variable 1>
,<
Split variable 2>
... - columns containing the categories by which the statistics were split by. The exact names will depend on the variables insplit.vars
. n_Cases - the number of cases in the sample used to compute the statistics for each split combination defined by the
split.vars
, if any, and thebckg.row.var
.Sum_
<
Weight variable>
- the estimated population number of elements per group after applying the weights. The actual name of the weight variable will depend on the weight variable used in the analysis.Sum_
<
Weight variable>
_
SE - the standard error of the the estimated population number of elements per group. The actual name of the weight variable will depend on the weight variable used in the analysis.Percentages_
<
Row variable>
- the percentages of respondents (population estimates) per groups defined by the splitting variables insplit.vars
, if any, and the row variable inbckg.row.var
. The percentages will be for the combination of categories in the last splitting variable and the row variable which define the final groups.Percentages_
<
Row variable>
_
SE - the standard errors of the percentages from above.Type - the type of computed values depending on the logical values passed to the
expected.cnts
,row.pcts
,column.pcts
, andtotal.pcts
arguments: "Observed count", "Expected count", "Row percent", "Column percent", and "Percent of total".-
<
Column variable name Category 1>
,<
Column variable name Category 1>
,... - the estimated values for all combinations between the row and column variables passed tobckg.row.var
andbckg.col.var
. There will be one column for each category of the column variable. -
<
Column variable name Category 1, 2,... n>
_
SE - the standard errors of the estimated values from the above. Total - the grand totals for each of the estimated value types ("Observed count", "Expected count", "Row percent", "Column percent", and "Percent of total") depending on the logical values (
TRUE
,FALSE
) passed to theexpected.cnts
,row.pcts
,column.pcts
, andtotal.pcts
arguments.Total
_
SE - the standard errors of the estimated values from the above.
The second sheet contains some additional information related to the analysis per country in the following columns:
-
<
Country ID>
- a column containing the names of the countries in the file for which statistics are computed. The exact column header will depend on the country identifier used in the particular study. -
<
Split variable 1>
,<
Split variable 2>
... - columns containing the categories by which the statistics were split by. The exact names will depend on the variables insplit.vars
. Statistics - contains the names of the different statistics types: chi-squares, degrees of freedom (sample and design), and p-values.
Value - the estimated values for the statistics from above.
The third sheet contains some additional information related to the analysis per country in the following columns:
DATA - used
data.file
ordata.object
.STUDY - which study the data comes from.
CYCLE - which cycle of the study the data comes from.
WEIGHT - which weight variable was used.
DESIGN - which resampling technique was used (JRR or BRR).
SHORTCUT - logical, whether the shortcut method was used.
NREPS - how many replication weights were used.
ANALYSIS_DATE - on which date the analysis was performed.
START_TIME - at what time the analysis started.
END_TIME - at what time the analysis finished.
DURATION - how long the analysis took in hours, minutes, seconds and milliseconds.
The fourth sheet contains the call to the function with values for all parameters as it was executed. This is useful if the analysis needs to be replicated later.
If graphs = TRUE
there will be an additional "Graphs" sheet containing all plots.
If any warnings resulting from the computations are issued, these will be included in an additional "Warnings" sheet in the workbook as well.
References
LaRoche, S., Joncas, M., & Foy, P. (2016). Sample Design in TIMSS 2015. In M. O. Martin, I. V. S. Mullis, & M. Hooper (Eds.), Methods and Procedures in TIMSS 2015 (pp. 3.1-3.37). Chestnut Hill, MA: TIMSS & PIRLS International Study Center.
LaRoche, S., Joncas, M., & Foy, P. (2017). Sample Design in PIRLS 2016. In M. O. Martin, I. V. S. Mullis, & M. Hooper (Eds.), Methods and Procedures in PIRLS 2016 (pp. 3.1-3.34). Chestnut Hill, MA: Lynch School of Education, Boston College.
Rao, J. N. K., & Scott, A. J. (1984). On Chi-Squared Tests for Multiway Contingency Tables with Cell Proportions Estimated from Survey Data. The Annals of Statistics, 12(1). https://doi.org/10.1214/aos/1176346391
Rao, J. N. K., & Scott, A. J. (1987). On Simple Adjustments to Chi-Square Tests with Sample Survey Data. The Annals of Statistics, 15(1), 385-397.
Skinner, C. (2019). Analysis of Categorical Data for Complex Surveys. International Statistical Review, 87(S1), S64-S78. https://doi.org/10.1111/insr.12285
See Also
Examples
# Compute two-way table between student sex and how much they proud they are proud to go to
# school using PIRLS 2016 student data.
## Not run:
lsa.crosstabs(data.file = "C:/Data/PIRLS_2016_G8_Student_Miss_to_NA.RData",
bckg.row.var = "ITSEX", bckg.col.var = "ASBG12E")
## End(Not run)
# Same as the above, this time also computing the expected counts, row percentages, column
# percentages, percentages of total.
## Not run:
lsa.crosstabs(data.file = "C:/Data/PIRLS_2016_G8_Student_Miss_to_NA.RData",
bckg.row.var = "ITSEX", bckg.col.var = "ASBG12E", expected.cnts = TRUE,
row.pcts = TRUE, column.pcts = TRUE, total.pcts = TRUE)
## End(Not run)