zi_fit_lm: Performs unpenalized/ridge logistic/linear regression.

Description Usage Arguments Details Value Examples

View source: R/zero_fit_pms.R

Description

Performs unpenalized/ridge logistic/linear regression.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
zi_fit_lm(
  y,
  X,
  binomial,
  intercept = TRUE,
  tol = 1e-08,
  maxit = 1e+05,
  seed = NULL,
  penalize_decider = function(X) {     ncol(X) >= nrow(X)/2 },
  pen_factors = NULL,
  nfits = 10,
  runs = 2,
  CV_or_BIC = FALSE
)

Arguments

y

The response vector.

X

The design matrix.

binomial

A logical. Fits a logistic regression if TRUE, otherwise a linear regression.

intercept

A logical, whether to include an intercept in the regression. Defaults to TRUE.

tol

A number, tolerance. Defaults to 1e-8. Passed to stats::glm() for penalized logistic regressions, or as the thresh argument to glmnet::glmnet() for both logistic and linear regressions if penalized.

maxit

An integer, the maximum number of iterations. Defaults to 100000. Passed to stats::glm() for penalized logistic regressions, or to glmnet::glmnet() for both logistic and linear regressions if penalized.

seed

The seed, passed to set.seed() before model fitting if not NULL. Defaults to NULL.

penalize_decider

A logical or a function that takes X and returns a logical. Defaults to function(X){ncol(X)>=nrow(X)/2}. Used to decide whether to use penalized l2 (ridge) regression (if TRUE). Note that if the fits for the unpenalized regression are almost perfect, a penalized regression will be automatically used.

pen_factors

A vector of non-negative numbers, defaults to NULL. Passed as the penalty.factor argument to glmnet::glmnet(). If intercept == TRUE, a 0 will be prepended.

nfits

A positive integer, defaults to 10. Used for penalized regressions, as number of folds if CV_BIC == TRUE (nfits argument to glmnet::cv.glmnet(), with nlambda set to 100), or the number of lambdas if BIC == FALSE (as the nlambda argument to glmnet::glmnet()).

runs

A positive integer, the number of reruns. The fit with the maximum likelihood will be returned. Defaults to 2.

CV_or_BIC

A logical, whether to use cross validation or BIC to choose the model from the path of penalized fits. Defaults to FALSE.

Details

See description of each argument.

Value

A list of following elements for the fitted model:

coefficients

The coefficients on columns of X. The coefficient on the intercept is prepended if intercept == TRUE.

logLik

The log likelihood.

sigmasq

The estimated variance (sigma squared). NULL if binomial == FALSE.

df

The effective degree of freedom.

Examples

1
2
3
4
5
6
7
8
9
m <- 5; n <- 100;
adj_mat <- ZiDAG::make_dag(m, mode = "chain")
d <- ZiDAG::gen_zero_dat(seed=1, gen_para="pms", adj_mat=adj_mat, n=n, gen_uniform_degree=1)
X <- full_design1(d$V[,2:m], d$Y[,2:m], right=paste(2:m),
         V_degree = 2, Y_degree = 2, Y_V_degree = 2)
zi_fit_lm(d$V[,1], X, TRUE)
zi_fit_lm(d$V[,1], X, penalize_decider=TRUE, TRUE, nfits=5, runs=1)
zi_fit_lm(d$Y[,1], X, FALSE)
zi_fit_lm(d$Y[,1], X, FALSE, penalize_decider=function(X){nrow(X)<100*ncol(X)}, nfits=5, runs=1)

sqyu/ZiDAG documentation built on Jan. 19, 2021, 4:11 p.m.