Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Suggests:
pscl,
knitr,
rmarkdown,
testthat
testthat,
rstudioapi
URL: https://github.com/qpsy/nonnest2
VignetteBuilder: knitr
RoxygenNote: 7.3.3
Expand Down
9 changes: 6 additions & 3 deletions R/llcont.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ llcont.glm <- function(x, ...){
switch(fam,
binomial = {
if(is.matrix(y)) {
n <- apply(y, 1, sum)
# Optimization: Using rowSums instead of apply for faster vectorized execution
n <- rowSums(y)
y <- ifelse(n == 0, 0, y[, 1]/n)
} else {
n <- rep.int(1, length(y))
Expand Down Expand Up @@ -339,7 +340,8 @@ llcont.polr <- function(x, ...) {
idx <- matrix(0, nrow=length(y), ncol=length(x$lev))
idx[wherey] <- 1

model.weights(m) * log(apply(idx * x$fitted.values, 1, sum))
# Optimization: Using rowSums instead of apply for faster vectorized execution
model.weights(m) * log(rowSums(idx * x$fitted.values))
}

################################################################
Expand Down Expand Up @@ -407,7 +409,8 @@ llcont.lavaan <- function(x, ...){
Mu.hat <- unclass(moments$mean)
} else {
## set mean structure to sample estimates
Mu.hat <- apply(x@Data@X[[g]], 2, mean)
# Optimization: Using colMeans instead of apply for faster vectorized execution
Mu.hat <- colMeans(x@Data@X[[g]])
}
llvec[grpind] <- dmvnorm(x@Data@X[[g]], Mu.hat, Sigma.hat, log=TRUE)

Expand Down
8 changes: 5 additions & 3 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
library(testthat)
library(nonnest2)
if (requireNamespace('testthat', quietly = TRUE)) {
library(testthat)
library(nonnest2)

test_check("nonnest2")
test_check('nonnest2')
}
Loading