Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use statmod package instead of hardcoded structs #18

Merged
merged 2 commits into from
Oct 12, 2023
Merged
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 @@ -21,5 +21,6 @@ Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Depends:
R (>= 2.10)
R (>= 2.10),
statmod
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(simulate_zero_inflated_beta_random_effect_data)
export(zibr)
importFrom(statmod,gauss.quad)
importFrom(stats,nlminb)
importFrom(stats,pchisq)
importFrom(stats,rbeta)
Expand Down
3 changes: 2 additions & 1 deletion R/fit_beta_regression_random_effect.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
calc_beta_loglik <- function(para, Z.aug, Y, subject.n, time.n,

Check warning on line 1 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=1,col=36,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.

Check warning on line 1 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=1,col=46,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.

Check warning on line 1 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=1,col=57,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.
prod.mat = prod.mat,

Check warning on line 2 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=2,col=28,[indentation_linter] Hanging indent should be 29 spaces but is 28 spaces.
Z.test.coeff.index,

Check warning on line 3 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=3,col=29,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.
gh.weights, gh.nodes, quad.n) {

Check warning on line 4 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=4,col=29,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.

Check warning on line 4 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=4,col=41,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.

Check warning on line 4 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=4,col=51,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.
### Y must be a vector here
Y <- as.vector(Y)
s2 <- para[1]
Expand Down Expand Up @@ -30,7 +30,7 @@
#### logY==0 -> infinite, we want to exclude Y==0 in the likelihood calculation
#### replace with infinite with 0, it will be ignored, e^0*e^log(p2)= p2
log.i[is.infinite(log.i)] <- 0
logL <- sum(

Check warning on line 33 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=33,col=3,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.
log(rowSums(gh.weights / sqrt(pi) * exp(prod.mat %*% log.i),
na.rm = TRUE
)),
Expand All @@ -56,8 +56,9 @@
#' }
#'
#' @importFrom stats nlminb pchisq
#' @importFrom statmod gauss.quad
fit_beta_random_effect <- function(Z = Z, Y = Y,
subject.ind = subject.ind, time.ind = time.ind,

Check warning on line 61 in R/fit_beta_regression_random_effect.R

View workflow job for this annotation

GitHub Actions / lint

file=R/fit_beta_regression_random_effect.R,line=61,col=36,[object_name_linter] Variable and function name style should match snake_case, symbols or UPPERCASE.
quad.n = 30, verbose = FALSE) {
Z <- as.matrix(Z)
Y <- as.matrix(Y)
Expand All @@ -79,7 +80,7 @@
ncol = subject.n * time.n)

#### generate quad points
gherm <- generate_gaussian_quad_points(quad.n)
gherm <- gauss.quad(quad.n, kind = "hermite")
gh.weights <- matrix(rep(gherm$weights, subject.n), nrow = subject.n, byrow = TRUE)
gh.nodes <- matrix(rep(gherm$nodes, subject.n * time.n),
nrow = subject.n * time.n, byrow = TRUE
Expand Down
3 changes: 2 additions & 1 deletion R/fit_logistic_regression_random_effect.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ calc_logistic_loglik <- function(para, X.aug, Y, subject.n, time.n,
#' }
#'
#' @importFrom stats nlminb pchisq
#' @importFrom statmod gauss.quad
fit_logistic_random_effect <- function(X = X, Y = Y,
subject.ind = subject.ind, time.ind = time.ind,
quad.n = 30, verbose = FALSE) {
Expand All @@ -68,7 +69,7 @@ fit_logistic_random_effect <- function(X = X, Y = Y,
ncol = subject.n * time.n)

#### generate quad points
gherm <- generate_gaussian_quad_points(quad.n)
gherm <- gauss.quad(quad.n, kind = "hermite")
gh.weights <- matrix(rep(gherm$weights, subject.n), nrow = subject.n, byrow = TRUE)
gh.nodes <- matrix(rep(gherm$nodes, subject.n * time.n),
nrow = subject.n * time.n, byrow = TRUE
Expand Down
3 changes: 2 additions & 1 deletion R/fit_zero_inflated_beta_regression_random_effect.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ calc_zibeta_loglik <- function(para,
#' }
#'
#' @importFrom stats nlminb pchisq
#' @importFrom statmod gauss.quad
fit_zero_inflated_beta_random_effect <- function(X = X, Z = Z, Y = Y,
subject_ind = subject_ind, time_ind = time_ind,
component_wise_test = TRUE,
Expand All @@ -81,7 +82,7 @@ fit_zero_inflated_beta_random_effect <- function(X = X, Z = Z, Y = Y,
ncol = subject.n * time.n)

#### generate quad points
gherm <- generate_gaussian_quad_points(quad_n)
gherm <- gauss.quad(quad_n, kind = "hermite")
gh.weights <- matrix(rep(gherm$weights, subject.n), nrow = subject.n, byrow = TRUE)
gh.nodes <- matrix(rep(gherm$nodes, subject.n * time.n),
nrow = subject.n * time.n, byrow = TRUE
Expand Down
151 changes: 0 additions & 151 deletions R/generate_gaussian_quad_points.R

This file was deleted.