| lpr_mover | R Documentation |
This function creates a dataframe which can then be input in lapop_mover() for comparing means across values of secondary variable(s) using LAPOP formatting.
lpr_mover(
data,
outcome,
grouping_vars,
rec = list(c(1, 1)),
rec2 = c(1, 1),
rec3 = c(1, 1),
rec4 = c(1, 1),
ci_level = 0.95,
mean = FALSE,
filesave = "",
cfmt = "",
ttest = FALSE,
keep_nr = FALSE
)
data |
A survey object. The data that should be analyzed. |
outcome |
Character. Outcome variable(s) of interest to be plotted across secondary variable(s). |
grouping_vars |
A character vector specifying one or more grouping variables. For each variable, the function calculates the average of the outcome variable, broken down by the distinct values within the grouping variable(s). |
rec |
Numeric. The minimum and maximum values of the frst outcome variable that should be included in the numerator of the percentage. For example, if the variable is on a 1-7 scale and rec is c(5, 7), the function will show the percentage who chose an answer of 5, 6, 7 out of all valid answers. Can also supply one value only, to produce the percentage that chose that value out of all other values. Default: c(1, 1). |
rec2 |
Numeric. Similar to 'rec' for the second outcome. Default: c(1, 1). |
rec3 |
Numeric. Similar to 'rec' for the third outcome. Default: c(1, 1). |
rec4 |
Numeric. Similar to 'rec' for the fourth outcome. Default: c(1, 1). |
ci_level |
Numeric. Confidence interval level for estimates. Default: 0.95 |
mean |
Logical. If TRUE, will produce the mean of the variable rather than recoding to percentage. Default: FALSE. |
filesave |
Character. Path and file name to save the dataframe as csv. |
cfmt |
Changes the format of the numbers displayed above the bars. Uses sprintf string formatting syntax. Default is whole numbers for percentages and tenths place for means. |
ttest |
Logical. If TRUE, will conduct pairwise t-tests for difference of means between all individual year-xvar levels and save them in attr(x, "t_test_results"). Default: FALSE. |
keep_nr |
Logical. If TRUE, will convert "don't know" (missing code .a) and "no response" (missing code .b) into valid data (value = 99) and use them in the denominator when calculating percentages. The default is to examine valid responses only. Default: FALSE. |
Returns a data frame, with data formatted for visualization by lapop_mover
Luke Plutowski, luke.plutowski@vanderbilt.edu && Robert Vidigal, robert.vidigal@vanderbilt.edu
require(lapop); data(ym23)
# Set SUrvey Context
ym23lpr<-lpr_data(ym23)
# Single DV
lpr_mover(data = ym23lpr,
outcome = "ing4",
grouping_vars = c("q1tc_r", "edre"),
rec = c(5, 7), ttest = FALSE)
# Multiple DV
lpr_mover(data = ym23lpr,
outcome = c("ing4", "pn4"),
grouping_vars = c("q1tc_r", "edre"),
rec = c(5, 7), rec2 = c(1, 2),
ttest = FALSE)
# Single DV X Single IV
lpr_mover(data = ym23lpr,
outcome="ing4",
grouping_vars="pn4",
rec=c(5,7),
ttest = FALSE)
# Multiple DV X Single IV
lpr_mover(data = ym23lpr,
outcome=c("ing4", "pn4"),
grouping_vars="edre",
rec=c(5,7), rec2=c(1,2),
ttest = FALSE)
# Multiple DV X Multiple IV
lpr_mover(data = ym23lpr,
outcome=c("ing4", "pn4"),
grouping_vars=c("edre", "q1tc_r"),
rec=c(5,7), rec2=c(1,2),
ttest = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.