| Title: | Explore Response Style in Survey Responding |
|---|---|
| Description: | Provides tools to fit the latent state and response style ('lasars') model to survey data using either Particle Metropolis within Gibbs ('pmwg') or maximum likelihood estimation. The package facilitates estimation of less-biased latent state and psychologically interpretable response style parameters. |
| Authors: | Jess Grimmond [aut, cre], Guy Hawkins [aut], Scott Brown [aut], Quentin Gronau [aut] |
| Maintainer: | Jess Grimmond <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-09-26 09:56:27 UTC |
| Source: | https://github.com/cran/lasars |
A small Big-5 dataset used in examples and vignettes.
example_lasars_dataexample_lasars_data
A data frame with 50 participants and 5 latent states:
Subject identifier
Survey item identifier
Chosen Likert scale response
Latent state identifier
Identifies positively- and reverse-scored items
Open Source Psychometrics
This function generates posterior-predictive data
gen_pp_data( sampled, n = 20, ll_func = sampled$ll_func, sampling_method = "pmwg", original_df = NULL, subject_colname = "subject", ... )gen_pp_data( sampled, n = 20, ll_func = sampled$ll_func, sampling_method = "pmwg", original_df = NULL, subject_colname = "subject", ... )
sampled |
A post-sampling object with parameter estimates. Should be the output of either run_lasars() or run_latstat() |
n |
the number of posterior samples being generated |
ll_func |
The likelihood function being used |
sampling_method |
A character string which reflects the sampling approach to be taken. Can take the value 'mle' or 'pmwg' |
original_df |
Necessary when sampling_method = 'mle'. Should be the original trial-wise data frame sampling was performed on |
subject_colname |
A character string representing the subject identifier variable |
... |
Additional parameters to pass into the pmwg run_stage calls |
A data frame
pp_data <- gen_pp_data(sampled = lasars_fit_result, n = 5)pp_data <- gen_pp_data(sampled = lasars_fit_result, n = 5)
Example pmwg fit for lasars model
lasars_fit_resultlasars_fit_result
A pmwg object with 100 iterations of 10 particles in each stage:
Original data used for fitting
A character vector of parameter names
The number of parameters listed in par_names
The number of subjects
A vector of subject identifiers
A list of priors
The likelihood function used for estimation
A list of subject (alphas), group (theta_mu) and covariance matrix (theta_sig) samples
The initialised pmwg object
The powerhouse of the lasars model - calculates the likelihood of the observed data, given the set of input parameters. If sample = TRUE, input parameters will be used to generate data.
lasars_ll_func( x, data, sample = FALSE, resp_opts, subject_colname, response_colname, latentState_colname, direction_colname = NULL, rev_score_id = NULL )lasars_ll_func( x, data, sample = FALSE, resp_opts, subject_colname, response_colname, latentState_colname, direction_colname = NULL, rev_score_id = NULL )
x |
A named vector of parameter estimates |
data |
A trial-wise data frame |
sample |
A boolean variable reflecting whether the ll func should evaluate likelihood or generate data |
resp_opts |
A numeric value representing the number of response options available in the scale |
subject_colname |
A character string representing the subject identifier variable |
response_colname |
A character string representing the chosen Likert scale response |
latentState_colname |
A character string representing the latent state identifier variable |
direction_colname |
A character string representing the reverse-coding variable |
rev_score_id |
A character string representing the level of the direction variable which indicates reverse-scored items |
A likelihood value
ll_func <- lasars_ll_func(x = c("mu.extra" = 0.2, "mu.open" = 0.1, "mu.consc" = 0.1, "mu.agree" = 0.2, "mu.neuro" = 0.1, "centrePref" = -.3, "oddsPref" = 0.2, "directionPref" = -0.5), data = example_lasars_data, resp_opts = 5, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE")ll_func <- lasars_ll_func(x = c("mu.extra" = 0.2, "mu.open" = 0.1, "mu.consc" = 0.1, "mu.agree" = 0.2, "mu.neuro" = 0.1, "centrePref" = -.3, "oddsPref" = 0.2, "directionPref" = -0.5), data = example_lasars_data, resp_opts = 5, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE")
The powerhouse of the latstat model - calculates the likelihood of the observed data, given the set of input parameters. If sample = TRUE, input parameters will be used to generate data.
latstat_ll_func( x, data, sample = FALSE, resp_opts, subject_colname, response_colname, latentState_colname, direction_colname, rev_score_id )latstat_ll_func( x, data, sample = FALSE, resp_opts, subject_colname, response_colname, latentState_colname, direction_colname, rev_score_id )
x |
A named vector of parameter estimates |
data |
A trial-wise data frame |
sample |
A boolean variable reflecting whether the ll func should evaluate likelihood or generate data |
resp_opts |
A numeric value representing the number of response options available in the scale |
subject_colname |
A character string representing the subject identifier variable |
response_colname |
A character string representing the chosen Likert scale response |
latentState_colname |
A character string representing the latent state identifier variable |
direction_colname |
A character string representing the reverse-coding variable |
rev_score_id |
A character string representing the level of the direction variable which indicates reverse-scored items |
A likelihood value
ll_func <- latstat_ll_func(x = c("mu.extra" = 0.2, "mu.open" = 0.1, "mu.consc" = 0.1, "mu.agree" = 0.2, "mu.neuro" = 0.1, "cut.1" = -0.3, "cut.2" = -0.2, "cut.4" = 0.5, sd = 0.3), data = example_lasars_data, resp_opts = 5, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE")ll_func <- latstat_ll_func(x = c("mu.extra" = 0.2, "mu.open" = 0.1, "mu.consc" = 0.1, "mu.agree" = 0.2, "mu.neuro" = 0.1, "cut.1" = -0.3, "cut.2" = -0.2, "cut.4" = 0.5, sd = 0.3), data = example_lasars_data, resp_opts = 5, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE")
Creates priors for pmwg sampling
make_priors( data, resp_opts, latentState_colname, est_directPref = NULL, mu_prior = 0, centrePref_prior = 0, oddsPref_prior = 0, directionPref_prior = 0, threshold_prior = 0, diag_prior = 1, analysis = "lasars" )make_priors( data, resp_opts, latentState_colname, est_directPref = NULL, mu_prior = 0, centrePref_prior = 0, oddsPref_prior = 0, directionPref_prior = 0, threshold_prior = 0, diag_prior = 1, analysis = "lasars" )
data |
A trial-wise data frame |
resp_opts |
A numeric value representing the number of response options available in the scale |
latentState_colname |
A character string representing the latent state identifier variable |
est_directPref |
A boolean value reflecting whether a directionPref parameter should be estimated |
mu_prior |
A numeric value representing the prior for the mu parameter |
centrePref_prior |
A numeric value representing the prior for the centrePref_prior parameter |
oddsPref_prior |
A numeric value representing the prior for the oddsPref parameter |
directionPref_prior |
A numeric value representing the prior for the directionPref parameter |
threshold_prior |
A numeric value representing the prior for the thresholds in the latstat model |
diag_prior |
A numeric value representing the prior for the diagonal |
analysis |
A character string taking the value of 'lasars' or 'latstat' which indicates which model variant is being used |
A list of priors
test_priors <- make_priors(data = example_lasars_data, resp_opts = 5, latentState_colname = "subscale", est_directPref = TRUE, mu_prior = 0.5, centrePref_prior = 0.3) test_priorstest_priors <- make_priors(data = example_lasars_data, resp_opts = 5, latentState_colname = "subscale", est_directPref = TRUE, mu_prior = 0.5, centrePref_prior = 0.3) test_priors
Estimates latent-state and response-style parameters from Likert-scale survey data.
run_lasars( data, resp_opts, est_directPref, subject_colname, response_colname, latentState_colname, direction_colname = NULL, rev_score_id = NULL, priors = NULL, sampling_method = "pmwg", iterations = 3000, particles = 50, ... )run_lasars( data, resp_opts, est_directPref, subject_colname, response_colname, latentState_colname, direction_colname = NULL, rev_score_id = NULL, priors = NULL, sampling_method = "pmwg", iterations = 3000, particles = 50, ... )
data |
A trial-wise data frame |
resp_opts |
A numeric value representing the number of response options available in the scale |
est_directPref |
A boolean value reflecting whether an directionPref parameter should be estimated |
subject_colname |
A character string representing the subject identifier variable |
response_colname |
A character string representing the chosen Likert scale response |
latentState_colname |
A character string representing the latent state identifier variable |
direction_colname |
A character string representing the reverse-coding variable |
rev_score_id |
A character string representing the level of the direction variable which indicates reverse-scored items |
priors |
A list of priors |
sampling_method |
A character string which reflects the sampling approach to be taken. |
iterations |
A numeric value reflecting the number of sampling iterations to run |
particles |
A numeric value reflecting the number of proposed particles on each sampling iteration |
... |
Additional parameters to pass into the pmwg run_stage calls |
A pmwg sampled object
lasars_fit_result <- run_lasars( data = example_lasars_data, resp_opts = 5, est_directPref = TRUE, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE", iterations = 100, particles = 10 )lasars_fit_result <- run_lasars( data = example_lasars_data, resp_opts = 5, est_directPref = TRUE, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE", iterations = 100, particles = 10 )
This function runs the model over the data
run_latstat( data, resp_opts, subject_colname, response_colname, latentState_colname, direction_colname, rev_score_id, priors = NULL, sampling_method = "pmwg", iterations = 3000, particles = 50, ... )run_latstat( data, resp_opts, subject_colname, response_colname, latentState_colname, direction_colname, rev_score_id, priors = NULL, sampling_method = "pmwg", iterations = 3000, particles = 50, ... )
data |
A trial-wise data frame |
resp_opts |
A numeric value representing the number of response options available in the scale |
subject_colname |
A character string representing the subject identifier variable |
response_colname |
A character string representing the chosen Likert scale response |
latentState_colname |
A character string representing the latent state identifier variable |
direction_colname |
A character string representing the reverse-coding variable |
rev_score_id |
A character string representing the level of the direction variable which indicates reverse-scored items |
priors |
A list of priors |
sampling_method |
A character string which reflects the sampling approach to be taken. Can take the value 'mle' or 'pmwg'. |
iterations |
A numeric value reflecting the number of sampling iterations to run |
particles |
A numeric value reflecting the number of proposed particles on each sampling iteration |
... |
Additional parameters to pass into the pmwg run_stage calls |
A pmwg sampled object
latstat_fit_result <- run_latstat( data = example_lasars_data, resp_opts = 5, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE", iterations = 100, particles = 10 )latstat_fit_result <- run_latstat( data = example_lasars_data, resp_opts = 5, subject_colname = "subject", response_colname = "response", latentState_colname = "subscale", direction_colname = "reverse", rev_score_id = "TRUE", iterations = 100, particles = 10 )