MixedModelsSim.jl
MixedModelsSim._update!MixedModelsSim.create_reMixedModelsSim.createθMixedModelsSim.cyclicshiftMixedModelsSim.factorproductMixedModelsSim.flatlowertriMixedModelsSim.nlevelsMixedModelsSim.nlevstblMixedModelsSim.pooled!MixedModelsSim.power_tableMixedModelsSim.simdat_crossedMixedModelsSim.update!MixedModelsSim.update!
MixedModelsSim._update! — Method_update!(m::MixedModel, θ)Update the mixed model to use θ as its new parameter vector.
This is a convenience function for installing a particular parameter vector and the resulting model fit. It does not actually perform any type of optimization.
For GLMMs, this only sets θ and not β, even for fast=false fits.
MixedModelsSim.create_re — Methodcreate_re(sigmas...; corrmat=Matrix{Float64}(I, length(sigmas), length(sigmas))Create the covariance factor for a random effect from the standard deviations and correlation matrix.
The sigmas should be specified in the same order as the random slopes in the output of VarCorr(m).
The correlation matrix defaults to the identity matrix, i.e. no correlation between random effects.
The return value is the lower Cholesky factor of the covariance matrix, which is what update! requires.
MixedModelsSim.createθ — Methodcreateθ(m::MixedModel; named_re)
create_theta(m::MixedModel; named_re)Create the parameter vector θ corresponding to the random effects.
The named_re can be created using create_re. The named_re are specified by the name of the blocking variable, e.g. subj=create_re(...).
The model must be specified because the parameters are sorted internally for computational efficiency.
MixedModelsSim.cyclicshift — Methodcyclicshift(v::AbstractVector, nrow)Return an eltype(v) matrix of size nrow by length(v) with each column consisting of v followed by a cyclic shift of v followed by ...
cyclicshift('a':'d', 8)MixedModelsSim.factorproduct — Methodfactorproduct(facs...)Return a Vector{NamedTuple} obtained by crossing facs....
The arguments should be coerceable to a Tables.RowTable with rowtable.
The value is a Tables.RowTable and hence can be converted to a DataFrame.
Example
julia> DataFrame(factorproduct((item=nlevels(3,'I'),), (subj=nlevels(5), age=["Y","Y","Y","O","O"])))
15×3 DataFrame
│ Row │ item │ subj │ age │
│ │ String │ String │ String │
├─────┼────────┼────────┼────────┤
│ 1 │ I1 │ S1 │ Y │
│ 2 │ I2 │ S1 │ Y │
│ 3 │ I3 │ S1 │ Y │
│ 4 │ I1 │ S2 │ Y │
│ 5 │ I2 │ S2 │ Y │
│ 6 │ I3 │ S2 │ Y │
│ 7 │ I1 │ S3 │ Y │
│ 8 │ I2 │ S3 │ Y │
│ 9 │ I3 │ S3 │ Y │
│ 10 │ I1 │ S4 │ O │
│ 11 │ I2 │ S4 │ O │
│ 12 │ I3 │ S4 │ O │
│ 13 │ I1 │ S5 │ O │
│ 14 │ I2 │ S5 │ O │
│ 15 │ I3 │ S5 │ O │MixedModelsSim.flatlowertri — Methodflatlowertri(::LowerTriangular)Returns the lower triangular flattened into 1D array in column-major order.
MixedModelsSim.nlevels — Functionnlevels(nlev, tag='S')Return a Vector{String} of tag followed by 1:nlev left-padded with zeros
Examples
julia> show(nlevels(10))
["S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09", "S10"]MixedModelsSim.nlevstbl — Methodnlevstbl(nm::Symbol, n, vars::Pair{Symbol, Vector{String}}...)Return a Tables.columntable with a nm column as a PooledArray with n levels.
If any vars pairs are given they are expanded to columns representing characteristics of the nm column. In experimental design terminology, if say nm is :item then these represent between-item experimental factors.
The nm column is generated as nlevels(n, uppercase(first(string(nm))))
Examples
julia> nlevstbl(:item, 10)
(item = ["I01", "I02", "I03", "I04", "I05", "I06", "I07", "I08", "I09", "I10"],)
julia> nlevstbl(:item, 9, :level => ["low", "medium", "high"])
(item = ["I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9"], level = ["low", "medium", "high", "low", "medium", "high", "low", "medium", "high"])MixedModelsSim.pooled! — Functionpooled!(df, cols::Type=Union{AbstractString,Missing})Like DataFrames.categorical! but converting columns to PooledArrays
This method is not type-specific in the first argument, in order to eliminate a dependency on DataFrames.jl. It nonetheless expects a DataFrame as its first argument
MixedModelsSim.power_table — Functionpower_table(sim, alpha = 0.05)Returns a row table with fields coefname and power based on the proportion of simulated p-values less than alpha, for sim, the output of parametricbootstrap.
MixedModelsSim.simdat_crossed — Methodsimdat_crossed([RNG], subj_n, item_n;
subj_btwn=nothing, item_btwn=nothing, both_win=nothing,
subj_prefix="S", item_prefix="I")Return a row table with a design specified by the:
- number of subjects (
subj_n), - number of items (
item_n) - between-subject factors (
subj_btwn) - between-item factors (
item_btwn) - within-subject/item factors (
both_win)
If a factor is both between-subject and between-item, put it in both subj_btwn and item_btwn with the same keys and the same levels.
Factors should be specified as dictionaries in the following format:
Dict(
:factor1_name => ["F1_level1", "F1_level2"],
:factor2_name => ["F2_level1", "F2_level2", "F2_level3"]
)In addition to design, the rowtable contains a field dv pre-populated with N(0,1) noise as a basis for further simulating a design.
The number of subjects/items must divide the number of combinations of between subject/item factor levels. In other words, this function assumes a balanced design and will throw an error if that is not possible.
MixedModelsSim.update! — Methodupdate!(m::MixedModel, re...)Update the mixed model to use the random-effects covariance matrices.
The re can be created using create_re.
They should be specified in the order specified in VarCorr(m).
We recommend against calling this method directly. Instead, use the method with keyword arguments to specify the different re by name.
This is a convenience function for installing a particular parameter vector and the resulting model fit. It does not actually perform any type of optimization.
Details
The re used as the λ fields of the model's ReTerms and should be specified as the lower Cholesky factor of covariance matrices.
MixedModelsSim.update! — Methodupdate!(m::MixedModel; namedre...)
update!(m::MixedModel; θ)Update the mixed model to use the random-effects covariance matrices.
The namedre can be created using create_re. The namedre are specified by the name of the blocking variable, e.g. subj=create_re(...).
Setting θ directly as a keyword-argument is deprecated.
This is a convenience function for installing a particular parameter vector and the resulting model fit. It does not actually perform any type of optimization.
Details
The re is used as the λ fields of the model's ReTerms and should be specified as the lower Cholesky factor of covariance matrices.