knitr::opts_chunk$set(comment = "#",collapse = TRUE,results = "hold", fig.align = "center")
Here we illustrate how to incorporate covariance regularization to unconstrained update. This is recommended when sample size is small and the number of condition is large.
library(udr)
set.seed(3) n = 20 R = 5 K = 2 Ut = c() for (k in 1:K){ Ut[[k]] <- udr:::sim_unconstrained(R) } Vt = diag(R) wt = rep(1/K, K) # Simulate data X <- simulate_ud_data(n,wt,Ut,Vt) X = as.matrix(X)
set.seed(999) U.init = c() for (i in 1:K) U.init[[i]] = udr:::sim_unconstrained(R) tol = 1e-2 tol.lik = 1e-2 lambda = 1 f0 <- ud_init(X, V = Vt, n_rank1 = 0, U_scaled = NULL, U_unconstrained = U.init)
In control list, specify (1) $\lambda$: the parameter that controls regularization strength; (2) penalty.type: either "iw" or "nu", where "iw" means inverse Wishart penalty and "nu" means nuclear norm penalty. In total, there are three algorithms that can be used:
ted.nu: TED algorithm with nuclear norm penalty;
ted.iw: TED algorithm with inverse Wishart penalty;
ed.iw: ED algorithm with inverse Wishart penalty.
ted.nu = ud_fit(f0, control = list(unconstrained.update = "ted", scaled.update = "fa", resid.update = 'none', lambda =lambda, penalty.type = "nu", maxiter=500, tol = tol, tol.lik = tol.lik), verbose=TRUE)
ted.iw = ud_fit(f0, control = list(unconstrained.update = "ted", scaled.update = "fa", resid.update = 'none', lambda =lambda, penalty.type = "iw", maxiter=500, tol = tol, tol.lik = tol.lik), verbose=TRUE)
ed.iw = ud_fit(f0, control = list(unconstrained.update = "ed", scaled.update = "fa", resid.update = 'none', lambda =lambda, penalty.type = "iw", maxiter=500, tol = tol, tol.lik = tol.lik), verbose=TRUE)
The penalized log-likelihood is guaranteed to increase every iteration.
plot(ted.nu$progress$loglik.pen, ylim = c(-200, -188), xlim = c(0, 20), xlab = "iteration", ylab = "Penalized log-likelihood") points(ted.iw$progress$loglik.pen, col = 2) points(ed.iw$progress$loglik.pen, col = 3) legend("bottomright", legend = c("ted.nu", "ted.iw", "ed.iw"), col = c(1:3), pch = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.