Skip to content

Commit

Permalink
screen coef Ridge lambda dep on family
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMAN PARZER committed Sep 16, 2024
1 parent 94dbaa7 commit c6b1ddd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: SPAR
Title: Sparse Projected Averaged Regression
Version: 3.1.1
Version: 3.2.0
Author: Roman Parzer and Laura Vana-Guer
Maintainer: Roman Parzer <[email protected]>
Description: Apply Sparse Projected Averaged Regression to
Expand Down
13 changes: 8 additions & 5 deletions R/screening_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ screening_ridge_lambda0 <- function(z, yz, family) {
tmp_sc <- apply(z,2,function(col)sqrt(var(col)*(n-1)/n))
z2 <- scale(z,center=colMeans(z),scale=tmp_sc)
lam_max <- 1000 * max(abs(t(yz)%*%z2[,tmp_sc>0]))/n*family$mu.eta(family$linkfun(mean(yz)))/family$variance(mean(yz))

glmnet_res <- glmnet::glmnet(x=z, y=yz, family = family, alpha=0,lambda.min.ratio = min(0.01,1e-7/n / lam_max))
lam <- min(glmnet_res$lambda)
if (family$family=="gaussian") {
dev.ratio_cutoff <- 0.999
} else {
dev.ratio_cutoff <- 0.8
}
glmnet_res <- glmnet::glmnet(x=z, y=yz, family = family, alpha=0,lambda.min.ratio = min(0.01,1e-4 / lam_max))
lam <- min(glmnet_res$lambda[glmnet_res$dev.ratio<=dev.ratio_cutoff])
scr_coef <- coef(glmnet_res,s=lam)[-1]

scr_coef
}

Expand All @@ -23,7 +26,7 @@ screening_marglik <- function(z, yz, family) {

screening_corr <- function(z, yz, family) {
n <- nrow(z)
if (family$family != "gaussian") warning("Screening based on correlation is typically employed for Gaussian variables.")
if (family != "gaussian") warning("Screening based on correlation is typically employed for Gaussian variables.")
scr_coef <- sapply(seq_len(NCOL(z)), function(i) cor(yz, z[,i]))
scr_coef
}
Expand Down

0 comments on commit c6b1ddd

Please sign in to comment.