Skip to content

Commit

Permalink
Updated calc_loglik() to use base R instead of {data.table} to define…
Browse files Browse the repository at this point in the history
… pred_expression_value and dist_squared, saving calculation time
  • Loading branch information
ruthkr committed Aug 27, 2023
1 parent c3a5b7e commit fc842c2
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions R/utils-calcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ calc_BIC <- function(logL, num_params, num_obs) {
#'
#' @noRd
calc_loglik <- function(model, data) {
# Suppress "no visible binding for global variable" note
expression_value <- NULL
pred_expression_value <- NULL

data <- data.table::copy(data)
# Read expression and variance
expression_value <- data$expression_value
sigma_squared <- data$var

# Predict expressions
data[, pred_expression_value := stats::predict(model, newdata = data)]
pred_expression_value <- stats::predict(model, newdata = data)
dist_squared <- (pred_expression_value - expression_value)^2

# Calculate logLik
data[, dist_squared := (pred_expression_value - expression_value)^2]

dist_squared <- data$dist_squared
sigma_squared <- data$var

loglik <- -sum(dist_squared / (2 * sigma_squared))

return(loglik)
Expand Down

0 comments on commit fc842c2

Please sign in to comment.