plot_expected_categorization: Plot prior and posterior categorization of test tokens for an...

View source: R/visualize-NIW-IA-stanfit.R

plot_expected_categorizationR Documentation

Plot prior and posterior categorization of test tokens for an NIW ideal adaptor stanfit

Description

Categorize test tokens by prior and/or posterior beliefs, and plot the resulting categorization function along a one-dimensional continuum (regardless of the dimensionality of the cue space in which categorization takes place). This provides the type of categorization plot typical for, for example, perceptual recalibration or phonetic tuning studies.

Usage

plot_expected_categorization(model, ...)

## S3 method for class 'ideal_adaptor_stanfit'
plot_expected_categorization(
  model,
  data.test = NULL,
  groups = get_group_levels(model, include_prior = T),
  lapse_treatment = c("no_lapses", "sample", "marginalize")[3],
  ndraws = NULL,
  target_category = 1,
  logit = F,
  confidence.intervals = c(0.66, 0.95),
  summarize = T,
  panel.group = if (plot_in_cue_space) TRUE else FALSE,
  group.colors = get_default_colors("group", groups),
  group.shapes = get_default_shapes("group", groups),
  group.linetypes = get_default_linetypes("group", groups),
  category.colors = get_default_colors("category", get_category_levels(model)),
  all_test_locations = TRUE,
  plot_in_cue_space = FALSE,
  plot_test_data = TRUE,
  sort_by = if ("prior" %in% groups) "prior" else NULL,
  untransform_cues = FALSE
)

Arguments

model

ideal_adaptor_stanfit object.

data.test

Optionally, a tibble or data.frame with test data. If 'NULL' the input will be extracted from fit. (default: 'NULL').

groups

Character vector of groups to be plotted. Typically, the levels of these factors are automatically added to the fit during the creation of the fit. If necessary, however, it is possible to use recover_types on the stanfit object to add or change these levels later. (default: all categories/groups will be plotted)

ndraws

Number of draws to plot (or use to calculate the CIs), or 'NULL' if all draws are to be returned. (default: 'NULL')

target_category

The index of the category for which categorization should be shown. (default: '1')

confidence.intervals

The two confidence intervals that should be plotted (using 'geom_ribbon') around the mean. (default: 'c(.66, .95)')

summarize

Should one categorization function (optionally with CIs) be plotted ('TRUE') or should separate unique categorization function be plotted for each MCMC draw ('FALSE')? (default: 'TRUE')

panel.group

Should the groups be plotted in separate panels? (default: 'FALSE')

group.colors, group.shapes, group.linetypes

Vector of colors, shapes, and linetypes of same length as 'groups' or 'NULL' to use defaults.

category.colors

Vector of colors and linetypes of same length as 'categories' or 'NULL' to use defaults. Only relevant when 'plot_in_cue_space = TRUE'.

all_test_locations

Should predictions be shown for all combinations of test locations and group, or should only combinations be shown that actually occurred in the data? (default: 'FALSE')

plot_in_cue_space

Currently only available if the model has one or two cues. Should predictions be plotted in the cue space? If not, test tokens are treated as factors and sorted along the x-axis based on 'sort_by'. (default: 'TRUE')

plot_test_data

Should the test data be plotted? If 'plot_in_cue_space = TRUE', then test data will be shown as points on top of the raster. If not, then pointranges will be shown. (default: 'TRUE')

sort_by

Which group, if any, should the x-axis be sorted by (in increasing order of posterior probability from left to right). Set to 0 for sorting by prior (default). Set to 'NULL' if no sorting is desired. (default: '"prior"')

untransform_cues

DEPRECATED. Should the cues be untransformed before plotting? This should only have visual consequences if 'plot_in_cue_space = T'. (default: 'FALSE')

Details

Tokens are sorted based on the increasing probability of a target_category response for the condition (group, e.g., prior or a specific exposure group) specified in sort_by. By default both the mean categorization and confidence intervals are plotted. If 'summarize=TRUE', the function marginalizes over all posterior samples. The number of samples is determined by ndraws. If ndraws is NULL, all samples are used. Otherwise ndraws random samples will be used. If 'summarize=FALSE', separate categorization plots for all ndraws individual samples will be plotted in separate panels.

Value

ggplot object.

See Also

TBD


hlplab/MVBeliefUpdatr documentation built on July 5, 2025, 6:42 a.m.