Skip to contents

This function creates a dataframe which can then be input in lapop_mline for to show a time series plot with multiple lines. If one "outcome" variable and an `xvar` variable is supplied, the function produces the values of a single outcome variable, broken down by a secondary variable, across time. If multiple outcome variables (up to four) are supplied, it will show means/percentages of those variables across time (essentially, it allows you to do lpr_ts for multiple variables).

Usage

lpr_mline(
  data,
  outcome,
  rec = c(1, 1),
  rec2 = c(1, 1),
  rec3 = c(1, 1),
  rec4 = c(1, 1),
  xvar,
  use_wave = FALSE,
  use_cat = FALSE,
  ci_level = 0.95,
  mean = FALSE,
  filesave = "",
  cfmt = "",
  ttest = FALSE,
  keep_nr = FALSE
)

Arguments

data

A survey object. The data that should be analyzed.

outcome

Character vector. Outcome variable(s) of interest to be plotted across time. If only one value is provided, the graph will show the outcome variable, over time, broken down by a secondary variable (x-var). If more than one value is supplied, the graph will show each outcome variable across time (no secondary variable).

rec, rec2, rec3, rec4

Numeric. The minimum and maximum values of the 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).

xvar

Character. Variable on which to break down the outcome variable. In other words, the line graph will produce multiple lines for each value of xvar (technically, it is the z-variable, not the x variable, which is year/wave). Ignored if multiple outcome variables are supplied.

use_wave

Logical. If TRUE, will use "wave" for the x-axis; otherwise, will use "year". Default: FALSE.

use_cat

Logical. If TRUE, will show the percentages of category values of a single variable; otherwise will show percentages of the range of values from rec(). Default FALSE.

ci_level

Numeric. Confidence interval level for estimates. Default: 0.95

mean

Logical. If TRUE, will produce the mean of the variable rather than rescaling to percentage. Default: FALSE.

filesave

Character. Path and file name to save the dataframe as csv.

cfmt

Character. 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 x 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.

Value

Returns a data frame, with data formatted for visualization by lapop_mline

Author

Luke Plutowski, luke.plutowski@vanderbilt.edu & Robert Vidigal, robert.vidigal@vanderbilt.edu

Examples


# Single Variable
if (FALSE) { # \dontrun{
lpr_mline(ym23,
outcome = "ing4",
rec = c(5, 7),
use_wave = FALSE)

# Multiple Variables
lpr_mline(cm23,
outcome = c("b13", "b18", "b21"),
rec = c(5, 7),
rec2 = c(1, 2),
rec3 = c(5, 7),
rec4 = c(1, 1),
use_wave = TRUE)

# Binary Single Variable by Category
lpr_mline(bra23,
outcome = "jc1",
use_cat = TRUE,
use_wave = TRUE)

# Recode Categorical Variable (max 4-categories)
lpr_mline(gm,
outcome = "a4n",
rec = c(1,4),
use_cat = TRUE,
use_wave = TRUE)} # }