
Core Functions
TrueAndErrorModels.@make_model — Macro
make_model model_type n_options n_repsGenerates a struct named model_type, constructors and a method for compute_probs based on n_options and n_reps. The struct for model_type and method for compute_probs includes auto-generated documentation.
Arguments
model_type: the name of the struct representing the model.n_options::Vector{Int}: the number of options in each choice set, e.g.,[2,3]indicates 2 options in
the first choice set and 3 in the second choice set.
n_reps: the number of times each choice set is presented. Each repetition occurs in seperate blocks with filler choices.
Example
using TrueAndErrorModels
@make_model MyCoolModel [2,2] 3
model = MyCoolModel(; p = [0.3, 0.40, 0.3, 0.0], ϵ = [0.4, 0.2, 0.2, 0.1])TrueAndErrorModels.compute_probs — Function
compute_probs(model::AbstractTrueErrorModel)
Computes the response probability for each response pattern.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
TrueAndErrorModels.get_error_parm_count — Function
get_error_parm_count(model::AbstractTrueErrorModel)
Returns the number of error parameters.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_error_parm_count(_::Type{<:AbstractTrueErrorModel})
Returns the number of error parameters.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_error_parm_labels — Function
get_error_parm_labels(model::AbstractTrueErrorModel)
Returns a vector of names corresponding to each error parameter.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_error_parm_labels(_::Type{<:AbstractTrueErrorModel})
Returns a vector of names corresponding to each error parameter.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_equations — Function
get_equations(model::AbstractTrueErrorModel)
Returns all model equations as a string.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_equations(_::Type{<:AbstractTrueErrorModel})
Returns all model equations as a string.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_equation_count — Function
get_equation_count(model::AbstractTrueErrorModel)
Returns the number of equations in the model which corresponds to the number of response patterns.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_equation_count(_::Type{<:AbstractTrueErrorModel})
Returns the number of equations in the model which corresponds to the number of response patterns.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_n_options — Function
get_n_options(model::AbstractTrueErrorModel)
Returns a vector where each element corresponds to the number of options in a choice set.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_n_options(_::Type{<:AbstractTrueErrorModel})
Returns a vector where each element corresponds to the number of options in a choice set.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_n_reps — Function
get_n_reps(model::AbstractTrueErrorModel)
Returns the number of times the choice sets are presented.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_n_reps(_::Type{<:AbstractTrueErrorModel})
Returns the number of times the choice sets are presented.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_response_labels — Function
get_response_labels(model::AbstractTrueErrorModel)
Returns a vector of labels for the response patterns.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_response_labels(_::Type{<:AbstractTrueErrorModel})
Returns a vector of labels for the response patterns.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_true_parm_labels — Function
get_true_parm_labels(model::AbstractTrueErrorModel)
Returns a vector of names corresponding to each true parameter.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_true_parm_labels(_::Type{<:AbstractTrueErrorModel})
Returns a vector of names corresponding to each true parameter.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
TrueAndErrorModels.get_true_parm_count — Function
get_true_parm_count(model::AbstractTrueErrorModel)
Returns the number of true parameters.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
get_true_parm_count(_::Type{<:AbstractTrueErrorModel})
Returns the number of true parameters.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
Distributions.logpdf — Function
logpdf(
dist::AbstractTrueErrorModel,
data::AbstractVector{<:Integer}
)
Computes the log loglikelihood of the data for a True and Error Model.
Arguments
dist::AbstractTrueErrorModel{T}: a distribution object for a True and Error Modeldata::AbstractVector{<:Integer}: a vector of response pattern frequencies.
Example
using TrueAndErrorModels
n_options = [2, 2]
n_reps = 2
@make_model TestModel n_options n_reps
model = TestModel(; p = [0.3, 0.40, 0.3, 0.0], ϵ = [0.4, 0.2, 0.2, 0.1])
data = rand(model, 100)
LL = logpdf(model, data)
TrueAndErrorModels.show_equations — Function
show_equations(model::AbstractTrueErrorModel)
Displays all model equations.
Arguments
model::AbstractTrueErrorModel: a generic true and error model
show_equations(_::Type{<:AbstractTrueErrorModel})
Displays all model equations.
Arguments
::Type{<:AbstractTrueErrorModel}: a generic true and error model type
Base.rand — Function
rand(
rng::Random.AbstractRNG,
dist::AbstractTrueErrorModel,
n_trials::Int64
)
Generate a vector of simulated response frequencies based on the provided True and Error Model.
dist::AbstractTrueErrorModel{T}: a distribution object for a True and Error Modeln_trials: the number of simulated trials
Output
data::Vector{<:Integer}: vector of joint response frequencies with the following elements:
Example
using TrueAndErrorModels
n_options = [2, 2]
n_reps = 2
@make_model TestModel n_options n_reps
model = TestModel(; p = [0.3, 0.40, 0.3, 0.0], ϵ = [0.4, 0.2, 0.2, 0.1])
data = rand(model, 100)Utilities
TrueAndErrorModels.to_table — Function
to_table(
model::Type{<:AbstractTrueErrorModel},
x::Vector;
labels
)
Transforms a vector into a joint response table in which each dimension represents choices in the corresponding block.
Example
using NamedArrays
using TrueAndErrorModels
n_options = [2, 2]
n_reps = 2
@make_model TestModel n_options n_reps
labels = get_response_labels(TestModel)
table = to_table(TestModel, labels)4×4 Named Matrix{String}
1 ╲ 2 │ (1,1) (2,1) (1,2) (2,2)
──────┼───────────────────────────────────────────────────────────
(1,1) │ "(1,1),(1,1)" "(1,1),(2,1)" "(1,1),(1,2)" "(1,1),(2,2)"
(2,1) │ "(2,1),(1,1)" "(2,1),(2,1)" "(2,1),(1,2)" "(2,1),(2,2)"
(1,2) │ "(1,2),(1,1)" "(1,2),(2,1)" "(1,2),(1,2)" "(1,2),(2,2)"
(2,2) │ "(2,2),(1,1)" "(2,2),(2,1)" "(2,2),(1,2)" "(2,2),(2,2)"