score2: Score With Small Sample Correction

score2R Documentation

Score With Small Sample Correction

Description

Extract the (individual) score a the latent variable model. Similar to lava::score but with small sample correction.

Usage

score2(object, indiv, cluster, as.lava, ...)

## S3 method for class 'lvmfit'
score2(
  object,
  indiv = FALSE,
  cluster = NULL,
  as.lava = TRUE,
  ssc = lava.options()$ssc,
  ...
)

## S3 method for class 'lvmfit2'
score2(object, indiv = FALSE, cluster = NULL, as.lava = TRUE, ...)

## S3 method for class 'lvmfit2'
score(x, indiv = FALSE, cluster = NULL, as.lava = TRUE, ...)

Arguments

object, x

a lvmfit or lvmfit2 object (i.e. output of lava::estimate or lavaSearch2::estimate2).

indiv

[logical] If TRUE, the score relative to each observation is returned. Otherwise the total score is returned.

cluster

[integer vector] the grouping variable relative to which the observations are iid.

as.lava

[logical] if TRUE, uses the same names as when using stats::coef.

...

additional argument passed to estimate2 when using a lvmfit object.

ssc

[character] method used to correct the small sample bias of the variance coefficients: no correction (code"none"/FALSE/NA), correct the first order bias in the residual variance ("residual"), or correct the first order bias in the estimated coefficients "cox"). Only relevant when using a lvmfit object.

Details

When argument object is a lvmfit object, the method first calls estimate2 and then extract the confidence intervals.

Value

When argument indiv is TRUE, a matrix containing the score relative to each sample (in rows) and each model coefficient (in columns). Otherwise a numeric vector of length the number of model coefficients.

See Also

estimate2 to obtain lvmfit2 objects.

Examples

#### simulate data ####
n <- 5e1
p <- 3
X.name <- paste0("X",1:p)
link.lvm <- paste0("Y~",X.name)
formula.lvm <- as.formula(paste0("Y~",paste0(X.name,collapse="+")))

m <- lvm(formula.lvm)
distribution(m,~Id) <- Sequence.lvm(0)
set.seed(10)
d <- lava::sim(m,n)

#### linear models ####
e.lm <- lm(Y~X1+X2+X3, data = d)

#### latent variable models ####
m.lvm <- lvm(formula.lvm)
e.lvm <- estimate(m.lvm,data=d)
e2.lvm <- estimate2(m.lvm,data=d)
score.tempo <- score(e2.lvm, indiv = TRUE)
colSums(score.tempo)


lavaSearch2 documentation built on April 12, 2023, 12:33 p.m.