Learn R Programming

psychonetrics (version 0.17.8)

allequal: Constrain all elements of a matrix equal within groups

Description

The allequal function constrains all free elements of a model matrix to be equal to one another within each group (a single shared parameter per group). In contrast to groupequal, which constrains corresponding elements equal across groups, allequal shares one parameter across the elements of the matrix and does so separately for each group, so the constraint is not imposed across groups. This is convenient for, for example, constraining all thresholds (tau) or all Blume-Capel quadratic potentials (delta) to a common value, or fitting an equal-edge-weight network (omega).

Usage

allequal(x, matrix, row, col, group, verbose, log = TRUE,
         runmodel = FALSE, identify = TRUE, ...)

Value

An object of the class psychonetrics (psychonetrics-class)

Arguments

x

A psychonetrics model.

matrix

String indicating the matrix whose elements should be constrained equal.

row

Optional integer or string vector indicating which rows of the matrix to include. Defaults to all rows.

col

Optional integer or string vector indicating which columns of the matrix to include. Defaults to all columns.

group

Optional vector of group ids to which the constraint is applied. Defaults to all groups (each constrained separately).

verbose

Logical, should messages be printed?

log

Logical, should the log be updated?

runmodel

Logical, should the model be updated?

identify

Logical, should the model be identified?

...

Arguments sent to runmodel

Author

Sacha Epskamp

Details

Only free parameters are affected; elements that are fixed (e.g. fixed to zero) are left unchanged. For symmetric matrices all free elements, including a free diagonal, are constrained equal; if this is not desired (for example to keep the diagonal separate from the off-diagonal elements), use the row and col arguments to restrict the constraint to the relevant elements. Within each group the selected free elements are given the same parameter number and a common starting value (the mean of their current values).

See Also

groupequal, parequal, fixpar

Examples

Run this code
if (FALSE) {
library("dplyr")

# Simulate a small Blume-Capel data set (requires the development version of
# IsingSampler that supports the 'delta' argument):
library("IsingSampler")
nNode  <- 5
graph  <- 0.4 * (matrix(1, nNode, nNode) - diag(nNode)) *
            (matrix(c(0,1,0,0,1, 1,0,1,0,0, 0,1,0,1,0, 0,0,1,0,1, 1,0,0,1,0), 5, 5))
data <- IsingSampler(1000, graph = graph, thresholds = rep(0, nNode),
                     beta = 1, delta = 1, responses = c(-1, 0, 1))

# Blume-Capel model with all quadratic (delta) potentials constrained equal,
# and all thresholds (tau) constrained equal, within the group:
mod <- BlumeCapel(data, responses = c(-1, 0, 1)) %>%
  allequal("delta") %>%
  allequal("tau") %>%
  runmodel
}

Run the code above in your browser using DataLab