add: df and AIC/BIC to Reg. Matrix Regression
This commit is contained in:
parent
2ddbe0e90d
commit
1531da7f19
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue