From 02549f7e786f1103d3a8b0caae874cb49efff4a2 Mon Sep 17 00:00:00 2001 From: Ben Dilday Date: Sun, 8 Apr 2018 09:24:38 -0400 Subject: [PATCH] refactored nd_min_fun moved the formula gneration and conversion of fixed effects to sparse out of the likelihood function. There's no need to redfine them between function calls and thsi gives a slight speed up. --- R/main.R | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/R/main.R b/R/main.R index 29be867..3db4f6f 100644 --- a/R/main.R +++ b/R/main.R @@ -205,17 +205,19 @@ nd_min_fun <- function(ev) { # make sure the data is a data frame, not a tibble ev$fr <- as.data.frame(ev$fr) + + glf <- lme4::glFormula(ev$frm, + data=ev$fr, family='binomial') + fe <- fixed_effects <- (glf$X) + re <- random_effects <- Matrix::t(glf$reTrms$Zt) + + y <- matrix(ev$fr[,all.vars(ev$frm)[[1]]], ncol=1) + k_class <- max(y) + k <- max(y) + Lind = glf$reTrms$Lind + fe2 <- Matrix::Matrix(fe, sparse = TRUE) function(mval) { - glf <- lme4::glFormula(ev$frm, - data=ev$fr, family='binomial') - fe <- fixed_effects <- (glf$X) - re <- random_effects <- Matrix::t(glf$reTrms$Zt) - - y <- matrix(ev$fr[,all.vars(ev$frm)[[1]]], ncol=1) - k_class <- max(y) - k <- max(y) - Lind = glf$reTrms$Lind s = 'mval ' for (v in mval) { @@ -229,8 +231,6 @@ nd_min_fun <- function(ev) { theta_mat <- matrix(mval, ncol=k_class) - fe2 <- Matrix::Matrix(fe, sparse = TRUE) - if (! "beta_re" %in% names(ev)) { ev$beta_re <- matrix(rnorm(ncol(re) * k_class, 0, 0.2), ncol=k_class) }