50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

PredTest (version 0.1.0)

pred_results: Predictive Results Wrapper Function

Description

This function is a wrapper that conditionally handles filtering by group or time, calculates the difference vector, and evaluates hypotheses to return a list of results.

Usage

pred_results(
  dataset,
  id = NULL,
  vars,
  type = "group",
  hypothesis,
  gtvar,
  grp_a,
  grp_b,
  location = "median",
  diff_method = "wilcoxon",
  phi_0 = 0.5
)

Value

A list containing:

results

A vector of 0s and 1s indicating whether each hypothesis was correct.

differences

A vector of the differences between groups.

variables

The column variables used in the analysis.

Arguments

dataset

A data frame for research.

id

The column that identifies unique subjects. This should be NULL if type is 'group' and should not be NULL if type is 'prepost'.

vars

The column variables of interest.

type

The type of study. Valid values are 'group' for group-based data and 'prepost' for pre-post data. Defaults to 'group'.

hypothesis

A vector or string of valid hypotheses: 'increase', 'decrease', or 'different'.

gtvar

The column of interest to divide the groups (e.g., time or treatment).

grp_a

The first subset of interest within the gtvar column (e.g., 'pre' or 'control').

grp_b

The second subset of interest within the gtvar column (e.g., 'post' or 'treatment').

location

The measure of central tendency to use for the difference calculation. Valid options are 'median' or 'mean'. Defaults to 'median'.

diff_method

The method to use for testing 'different' hypotheses. Valid options are 'wilcoxon' or 't'. Defaults to 'wilcoxon'.

phi_0

The decision rule threshold for the p-value. If p-value < phi_0, then there's sufficient evidence for a success for a difference. Defaults to 0.50.

Details

This function performs error handling to ensure appropriate input values and types. It then filters the data based on the study type, calculates the difference vector, and evaluates the hypotheses using the specified method.

Examples

Run this code
data("group_data_example")
data("group_cog_data")
data("pre_post_data_example")
data("pre_post_fit")

# simple group analysis
pred_results(dataset=group_data_example, vars=c('v1', 'v2'),
hypothesis=c("increase", "different"), gtvar="group", grp_a="placebo", grp_b="drug")

# simple prepost analysis
pred_results(dataset=pre_post_data_example, id="ID", vars=c('v1', 'v2', 'v3'),
type="prepost", hypothesis="increase", gtvar="time", grp_a=0, grp_b=12)

# simulated group analysis
pred_results(dataset=group_cog_data, vars=c('blind_moca_uncorrected', 'craft_verbatim'),
type="group", hypothesis="decrease", gtvar="group.factor", grp_a="Control", grp_b="ESKD")

# simulated prepost analysis
pred_results(dataset=pre_post_fit, id="ID", vars=c('Flex_right', 'Flex_left'),
type="prepost", hypothesis="increase", gtvar="Time", grp_a=0, grp_b=1)

Run the code above in your browser using DataLab