add: df and AIC/BIC to Reg. Matrix Regression

This commit is contained in:
Daniel Kapla 2021-12-09 18:29:04 +01:00
parent 2ddbe0e90d
commit 1531da7f19
1 changed files with 12 additions and 9 deletions

View File

@ -149,8 +149,14 @@ RMReg <- function(X, Z, y, lambda = 0,
a1 <- alpha(a1, iter)
}
# ### Degrees of Freedom estimate
# df <-
### Degrees of Freedom estimate (TODO: this is like in `matrix_sparsereg.m`)
sigma <- c(La.svd(A, 0, 0)$d, rep(0, max(shape) - min(shape)))
df <- if (!is.null(ZZiZ)) { ncol(Z) } else { 0 }
for (i in seq_len(sum(b1 > 0))) {
df <- df + 1 + sigma[i] * (sigma[i] - delta * lambda) * (
sum(ifelse((1:shape[1]) != i, 1 / (sigma[i]^2 - sigma[1:shape[1]]^2), 0)) +
sum(ifelse((1:shape[2]) != i, 1 / (sigma[i]^2 - sigma[1:shape[2]]^2), 0)))
}
# return estimates and some additional stats
list(
@ -158,13 +164,10 @@ RMReg <- function(X, Z, y, lambda = 0,
beta = if(is.null(ZZiZ)) { NULL } else { beta },
singular.values = b1,
iter = iter,
df = "?",
AIC = "?",
BIC = "?",
df = df,
loss = loss1,
AIC = loss1 / var(y) + 2 * df,
BIC = loss1 / var(y) + log(nrow(X)) * df,
call = match.call() # invocing function call, collects params like lambda
)
}
rmr.fit <- RMReg(X, NULL, y, lambda = 0)
rmr.fit$iter
rmr.fit$singular.values[rmr.fit$singular.values > 0]