View source: R/cglasso_S3methods.R
residuals | R Documentation |
Extracts model residuals from an R object inheriting class ‘cglasso
’.
## S3 method for class 'cglasso' residuals(object, type = c("observed", "working"), lambda.id, rho.id, drop = TRUE, ...)
object |
an R object inheriting class ‘ |
type |
a description of the desired residuals (see section ‘Details’). |
lambda.id |
a vector of integers used to specify the lambda-values. |
rho.id |
a vector of integers used to specify the rho-values. |
drop |
logical. Dimensions can only be dropped if their extent is one. |
... |
further arguments passed to or from other methods. |
The accessor function ‘residuals
’ returns an array storing the ‘observed’ or ‘working’ residuals, depending on the argument type
.
The ‘observed’ residuals are defined as the difference between the observed response values and the corresponding fitted expected values. For missing and censored response values, the ‘observed’ residuals are set equal to ‘NA
’.
The ‘working’ residuals are obtained as a byproduct of the EM-algorithm used to fit the model. In the E-step, the algorithm computes the ‘working’ response matrix, that is, the response matrix with missing values replaced by the conditional expected values of the multivariate normal distribution and censored values replaced by the conditional expected values of the multivariate truncated normal distribution. The ‘working’ residuals are defined as the difference between ‘working’ responses and fitted expected values.
The accessor function ‘residuals
’ returns an array storing the desired residuals.
Luigi Augugliaro (luigi.augugliaro@unipa.it)
Model-fitting functions cglasso
, cggm
and the accessor functions coef.cglasso
, fitted.cglasso
, predict.cglasso
and impute
.
set.seed(123) # Y ~ N(0, Sigma) and probability of left/right censored values equal to 0.05 n <- 1000L p <- 3L rho <- 0.3 Sigma <- outer(1L:p, 1L:p, function(i, j) rho^abs(i - j)) Z <- rcggm(n = n, Sigma = Sigma, probl = 0.05, probr = 0.05) out <- cglasso(. ~ ., data = Z) residuals(out, type = "observed", rho.id = 3L, drop = TRUE) residuals(out, type = "working", rho.id = 3L, drop = TRUE) # Y ~ N(b0 + XB, Sigma) and probability of left/right censored values equal to 0.05 n <- 1000L p <- 3L q <- 2 b0 <- runif(p) B <- matrix(runif(q * p), nrow = q, ncol = p) X <- matrix(rnorm(n * q), nrow = n, ncol = q) rho <- 0.3 Sigma <- outer(1L:p, 1L:p, function(i, j) rho^abs(i - j)) Z <- rcggm(n = n, b0 = b0, X = X, B = B, Sigma = Sigma, probl = 0.05, probr = 0.05) out <- cglasso(. ~ ., data = Z) residuals(out, type = "observed", lambda.id = 3L, rho.id = 3L, drop = TRUE) residuals(out, type = "working", lambda.id = 3L, rho.id = 3L, drop = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.