lsa.pcts.means {RALSA} | R Documentation |
Compute percentages of respondents in groups and/or means (arithmetic average, median or mode) on continuous variables within specified groups
Description
lsa.pcts.means
computes percentages of respondents within groups defined by one or more variables and the means for one or more variables.
Usage
lsa.pcts.means(
data.file,
data.object,
split.vars,
bckg.avg.vars,
PV.root.avg,
central.tendency,
weight.var,
include.missing = FALSE,
shortcut = FALSE,
graphs = FALSE,
perc.x.label = NULL,
perc.y.label = NULL,
mean.x.labels = NULL,
mean.y.labels = NULL,
save.output = TRUE,
output.file,
open.output = TRUE
)
Arguments
data.file |
The file containing |
data.object |
The 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.avg.vars |
Name(s) of continuous background or contextual variable(s) to compute the means for. The results will be computed by all groups specified by the splitting variables. See details. |
PV.root.avg |
The root name(s) for the set(s) of plausible values. See details. |
central.tendency |
Which measure of central tendency shall be computed - |
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 PSI, PIRLS, ePIRLS, PIRLS Literacy and RLII be
applied? The default ( |
graphs |
Logical, shall graphs be produced? Default is |
perc.x.label |
String, custom label for the horizontal axis in percentage graphs.
Ignored if |
perc.y.label |
String, custom label for the vertical axis in percentage graphs.
Ignored if |
mean.x.labels |
List of strings, custom labels for the horizontal axis in means' graphs.
Ignored if |
mean.y.labels |
List of strings, custom labels for the vertical axis in means' 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 percentages of respondents specified by the categories of splitting variables. The percentages are computed within the groups specified by the last splitting variable. If a continuous variable(s) are provided (background or sets of plausible values), their means (as arithmetic means, medians or modes) will be computed by groups defined by one or more splitting variables. 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.
Multiple continuous background variables can be provided to compute their means (as arithmetic means, medians or modes). Please note that in this case the results will slightly differ compared to using each of the same background continuous variables in separate analyses. This is because the cases with the missing values on bckg.avg.vars
are removed in advance and the more variables are provided to bckg.avg.vars
, the more cases are likely to be removed.
Computation of means involving plausible values requires providing a root of the plausible values names in PV.root.avg
. All studies (except CivED, TEDS-M, SITES, TALIS and TALIS Starting Strong Survey) have a set of PVs per construct (e.g. in TIMSS five for overall mathematics, five for algebra, five for geometry, etc.). In some studies (say TIMSS and PIRLS) the names of the PVs in a set always start with character string and end with sequential number of the PV. For example, the names of the set of PVs for overall mathematics in TIMSS are BSMMAT01, BSMMAT02, BSMMAT03, BSMMAT04 and BSMMAT05. The root of the PVs for this set to be added to PV.root.avg
will be "BSMMAT". The function will automatically find all the variables in this set of PVs and include them in the analysis. In other studies like OECD PISA and IEA ICCS and ICILS the sequential number of each PV is included in the middle of the name. For example, in ICCS the names of the set of PVs are PV1CIV, PV2CIV, PV3CIV, PV4CIV and PV5CIV. The root PV name has to be specified in PV.root.avg
as "PV#CIV". More than one set of PVs can be added. Note, however, that providing continuous variable(s) for the bckg.avg.vars
argument and root PV for the PV.root.avg
argument will affect the results for the PVs because the cases with missing on bckg.avg.vars
will be removed and this will also affect the results from the PVs. On the other hand, using more than one set of PVs at the same time should not affect the results on any PV estimates because PVs shall not have any missing values.
If no variables are specified for bckg.avg.vars
, and no PV root names for PV.root.avg
, the output will contain only percentages of cases in groups specified by the splitting variables, if any. If they are, their means will be computed either as arithmetic means, medians or modes. This can be controlled by setting the central.tendency
argument to mean
(default), median
or mode
. Note that if central.tendency = "mode"
and the variables passed to bckg.avg.vars
or the sets of PVs passed to PV.root.avg
have more than one mode, the value for the lowest value will be included in the output. As a conseequence, the standard errors may be inflated.
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 PSI, 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 replication of the tables and figures is needed, the shortcut
argument has to be changed to TRUE
.
If graphs = TRUE
, the function will produce graphs. If only split.vars
are specified, bar plots of percentages of respondents (population estimates) per group will be produced with error bars (95% confidence) for these percentages. If bckg.avg.vars
and/or PV.root.avg
are specified, plots with 95% confidence intervals of the averages (means, medians or modes) will be produced for each average analysis variable. All plots are produced per country. If bckg.avg.vars
and/or PV.root.avg
are specified, but no split.vars
at the end there will be plots for each of the analysis average variables for all countries together. By default the percentage graphs horizontal axis is labeled with the name of the last splitting variable, and the vertical is labeled as "Percentages XXXXX" where XXXXX is the last splitting variable the percentages are computed for. For the means' plots the horizontal axis is labeled as the name of the last splitting variable for whose categories the means are computed by, and the vertical axis is labeled as "Mean XXXXX" where XXXXX is the name of the variable for which means are computed. These defaults can be overriden by supplying values to perc.x.label
, perc.y.label
, mean.x.labels
and mean.y.labels
. The perc.x.label
and perc.y.label
arguments accept vectors of length 1, and if longer vectors are supplied, error is thrown. The mean.x.labels
and mean.y.labels
accept lists with number of components equal to the number of variables (background or PVs) for which means are computed, longer or shorter lists throw errors. See the examples.
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 which will be used to label the axes.
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 three 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.
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_
<
Last split variable>
- the percentages of respondents (population estimates) per groups defined by the splitting variables insplit.vars
. The percentages will be for the last splitting variable which defines the final groups.Percentages_
<
Last split variable>
_
SE - the standard errors of the percentages from above.Mean_
<
Background variable>
- returned ifcentral.tendency = "mean"
, the arithmetic average of the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the arithmetic average estimate for each variable specified inbckg.avg.vars
.Mean_
<
Background variable>
_
SE - returned ifcentral.tendency = "mean"
, the standard error of the arithmetic average of the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the SE of the average estimate for each variable specified inbckg.avg.vars
.Variance_
<
Background variable>
- returned ifcentral.tendency = "mean"
, the variance for the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the variance estimate for each variable specified inbckg.avg.vars
.Variance_
<
Background variable>
_
SE - returned ifcentral.tendency = "mean"
, the error of the variance for the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the error of the variance estimate for each variable specified inbckg.avg.vars
.SD_
<
Background variable>
- returned ifcentral.tendency = "mean"
, the standard deviation for the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the standard deviation estimate for each variable specified inbckg.avg.vars
.SD_
<
Background variable>
_
SE - returned ifcentral.tendency = "mean"
, the error of the standard deviation for the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the error of the standard deviation estimate for each variable specified inbckg.avg.vars
.Median_
<
Background variable>
- returned ifcentral.tendency = "median"
, the median of the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the median estimate for each variable specified inbckg.avg.vars
.Median_
<
Background variable>
_
SE - returned ifcentral.tendency = "median"
, the standard error of the median of the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the SE of the median estimate for each variable specified inbckg.avg.vars
.MAD_
<
Background variable>
- returned ifcentral.tendency = "median"
, the Median Absolute Deviation (MAD) for the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the MAD estimate for each variable specified inbckg.avg.vars
.MAD_
<
Background variable>
_
SE - returned ifcentral.tendency = "median"
, the standard error of MAD for the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the MAD SE estimate for each variable specified inbckg.avg.vars
.Mode_
<
Background variable>
- returned ifcentral.tendency = "mode"
, the mode of the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the mode estimate for each variable specified inbckg.avg.vars
.Mode_
<
Background variable>
_
SE - returned ifcentral.tendency = "mode"
, the standard error of the mode of the continuous<
Background variable>
specified inbckg.avg.vars
. There will be one column with the SE of the mode estimate for each variable specified inbckg.avg.vars
.Percent_Missings_
<
Background variable>
- the percentage of missing values for the<
Background variable>
specified inbckg.avg.vars
. There will be one column with the percentage of missing values for each variable specified inbckg.avg.vars
.Mean_
<
root PV>
- returned ifcentral.tendency = "mean"
, the arithmetic average of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the arithmetic average estimate for each set of PVs specified inPV.root.avg
.Mean_
<
root PV>
_
SE - returned ifcentral.tendency = "mean"
, the standard error of the arithmetic average of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the standard error of arithmetic average estimate for each set of PVs specified inPV.root.avg
.Mean_
<
root PV>
_
SVR - returned ifcentral.tendency = "mean"
, the sampling variance component for the arithmetic average of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the sampling variance component for the arithmetic average estimate for each set of PVs specified inPV.root.avg
.Mean_
<
root PV>
_
MVR - returned ifcentral.tendency = "mean"
, the measurement variance component for the arithmetic average of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the measurement variance component for the arithmetic average estimate for each set of PVs specified inPV.root.avg
.Variance_
<
root PV>
- returned ifcentral.tendency = "mean"
, the total variance of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the total variance of each set of PVs specified inPV.root.avg
.Variance_
<
root PV>
_
SE - returned ifcentral.tendency = "mean"
, the standard error of the total variance of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the standard error of the total variance of each set of PVs specified inPV.root.avg
.Variance_
<
root PV>
_
SVR - returned ifcentral.tendency = "mean"
, the sampling component of the variance of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the sampling component of the variance of each set of PVs specified inPV.root.avg
.Variance_
<
root PV>
_
MVR - returned ifcentral.tendency = "mean"
, the measurement component of the variance of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the measurement component of the variance of each set of PVs specified inPV.root.avg
.SD_
<
root PV>
- returned ifcentral.tendency = "mean"
, the standard deviation of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the standard deviation of each set of PVs specified inPV.root.avg
.SD_
<
root PV>
_
SE - returned ifcentral.tendency = "mean"
, the standard error of the standard deviation of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the standard error of the standard deviation of each set of PVs specified inPV.root.avg
.SD_
<
root PV>
_
SVR - returned ifcentral.tendency = "mean"
, the sampling component of the standard deviation of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the sampling component of the standard deviation of each set of PVs specified inPV.root.avg
.SD_
<
root PV>
_
MVR - returned ifcentral.tendency = "mean"
, the measurement component of the standard deviation of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the measurement component of the standard deviation of each set of PVs specified inPV.root.avg
.Median_
<
root PV>
- returned ifcentral.tendency = "median"
, the median of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the median estimate for each set of PVs specified inPV.root.avg
.Median_
<
root PV>
_
SE - returned ifcentral.tendency = "median"
, the standard error of the median of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the standard error of median estimate for each set of PVs specified inPV.root.avg
.MAD_
<
root PV>
- returned ifcentral.tendency = "median"
, the Median Absolute Deviation (MAD) for a set of PVs specified inPV.root.avg
. There will be one column with the MAD estimate for each set of PVs specified inPV.root.avg
.MAD_
<
root PV>
_
SE - returned ifcentral.tendency = "median"
, the standard error of MAD for a set of PVs specified inPV.root.avg
. There will be one column with the SE estimate of the MAD for each set of PVs specified inPV.root.avg
.Mode_
<
root PV>
- returned ifcentral.tendency = "mode"
, the mode of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the mode estimate for each set of PVs specified inPV.root.avg
.Mode_
<
root PV>
_
SE - returned ifcentral.tendency = "mode"
, the standard error of the mode of the PVs with the same<
root PV>
specified inPV.root.avg
. There will be one column with the standard error of mode estimate for each set of PVs specified inPV.root.avg
.Percent_Missings_
<
root PV>
- the percentage of missing values for the<
root PV>
specified inPV.root.avg
. There will be one column with the percentage of missing values for each set of PVs specified inPV.root.avg
.
The second 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 third 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.
See Also
Examples
# Compute percentages of female and male students in TIMSS 2015 grade 8 using data file, omit
# missing from the splitting variable (female and male as answered by the students), without
# shortcut, and open the output after the computations are done
## Not run:
lsa.pcts.means(data.file = "C:/Data/TIMSS_2015_G8_Student_Miss_to_NA.RData",
split.vars = "BSBG01", include.missing = FALSE,
output.file = "C:/temp/test.xlsx", open.output = TRUE)
## End(Not run)
# Compute the arithmetic average of the complex background scale "Students like learning
# mathematics" by student sex and frequency of using computer or tablet at home using TIMSS
# 2015 grade 8 data loaded in memory, using the shortcut, include the missing values in
# the splitting variables, and use the senate weights
## Not run:
lsa.pcts.means(data.object = T15_G8_student_data, split.vars = c("BSBG01", "BSBG13A"),
bckg.avg.vars = "BSBGSLM", weight.var = "SENWGT", include.missing = FALSE, shortcut = TRUE,
output.file = "C:/temp/test.xlsx", open.output = TRUE)
## End(Not run)
# Repeat the analysis from above, adding a second continuous variable to compute the arithmetic
# average for, the "Students Like Learning Science" complex scale
## Not run:
lsa.pcts.means(data.object = T15_G8_student_data, split.vars = c("BSBG01", "BSBG13A"),
bckg.avg.vars = c("BSBGSLM", "BSBGSLS"), weight.var = "SENWGT", include.missing = FALSE,
shortcut = TRUE, output.file = "C:/temp/test.xlsx", open.output = TRUE)
## End(Not run)
# Same as above, but add graphs with custom labels for the percentages and means
## Not run:
lsa.pcts.means(data.object = T15_G8_student_data, split.vars = c("BSBG01", "BSBG13A"),
bckg.avg.vars = c("BSBGSLM", "BSBGSLS"), weight.var = "SENWGT", include.missing = FALSE,
shortcut = TRUE, graphs = TRUE,
perc.x.label = "Using computer or tables for schoolwork at home",
perc.y.label = "Percentage of students",
mean.x.labels = list("Books at home", "Books at home"),
mean.y.labels = list("Average like learning math", "Average like learning science"),
output.file = "C:/temp/test.xlsx", open.output = TRUE)
## End(Not run)
# Compute the arithmetic average of student overall reading achievement scores
# (i.e. using a set of PVs), using PIRLS 2016 student data file, split the output by student
# sex, use the full design, include the missing values od the splitting variable
# (i.e. student sex), and do not open the output after the computations are finished
## Not run:
lsa.pcts.means(data.file = "C:/Data/PIRLS_2016_Student_Miss_to_NA.RData", split.vars = "ASBG01",
PV.root.avg = "ASRREA", include.missing = TRUE,
output.file = "C:/temp/test.xlsx", open.output = FALSE)
## End(Not run)
# Same as above, this time compute the median instead of the arithmetic average
## Not run:
lsa.pcts.means(data.file = "C:/Data/PIRLS_2016_Student_Miss_to_NA.RData", split.vars = "ASBG01",
PV.root.avg = "ASRREA", include.missing = TRUE,
central.tendency = "median",
output.file = "C:/temp/test.xlsx", open.output = FALSE)
## End(Not run)