Package {lasars}


Title: Explore Response Style in Survey Responding
Version: 0.1.1
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.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: purrr, pmwg, stats
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
Depends: R (≥ 3.5)
LazyData: true
NeedsCompilation: no
Packaged: 2026-08-21 05:20:20 UTC; jkg582
Author: Jess Grimmond [aut, cre], Guy Hawkins [aut], Scott Brown [aut], Quentin Gronau [aut]
Maintainer: Jess Grimmond <jess.grimmond@newcastle.edu.au>
Repository: CRAN
Date/Publication: 2026-08-27 10:10:02 UTC

Example dataset for lasars

Description

A small Big-5 dataset used in examples and vignettes.

Usage

example_lasars_data

Format

A data frame with 50 participants and 5 latent states:

subject

Subject identifier

item

Survey item identifier

response

Chosen Likert scale response

subscale

Latent state identifier

reverse

Identifies positively- and reverse-scored items

Source

Open Source Psychometrics


Generates posterior samples

Description

This function generates posterior-predictive data

Usage

gen_pp_data(
  sampled,
  n = 20,
  ll_func = sampled$ll_func,
  sampling_method = "pmwg",
  original_df = NULL,
  subject_colname = "subject",
  ...
)

Arguments

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

Value

A data frame

Examples

pp_data <- gen_pp_data(sampled = lasars_fit_result,
                       n = 5)


Example pmwg fit for lasars model

Description

Example pmwg fit for lasars model

Usage

lasars_fit_result

Format

A pmwg object with 100 iterations of 10 particles in each stage:

data

Original data used for fitting

par_names

A character vector of parameter names

n_pars

The number of parameters listed in par_names

n_subject

The number of subjects

subject

A vector of subject identifiers

prior

A list of priors

ll_func

The likelihood function used for estimation

samples

A list of subject (alphas), group (theta_mu) and covariance matrix (theta_sig) samples

init

The initialised pmwg object


Likelihood function for lasars Model

Description

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.

Usage

lasars_ll_func(
  x,
  data,
  sample = FALSE,
  resp_opts,
  subject_colname,
  response_colname,
  latentState_colname,
  direction_colname = NULL,
  rev_score_id = NULL
)

Arguments

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

Value

A likelihood value

Examples

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")


Likelihood function for Latent State Only Model

Description

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.

Usage

latstat_ll_func(
  x,
  data,
  sample = FALSE,
  resp_opts,
  subject_colname,
  response_colname,
  latentState_colname,
  direction_colname,
  rev_score_id
)

Arguments

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

Value

A likelihood value

Examples

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")

Make pmwg priors

Description

Creates priors for pmwg sampling

Usage

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"
)

Arguments

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

Value

A list of priors

Examples

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_priors


Fit the lasars model

Description

Estimates latent-state and response-style parameters from Likert-scale survey data.

Usage

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,
  ...
)

Arguments

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

Value

A pmwg sampled object

Examples


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
)



Runs the latent state only model

Description

This function runs the model over the data

Usage

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,
  ...
)

Arguments

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

Value

A pmwg sampled object

Examples


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
)