Skip to content

Commit

Permalink
update to R-squared computation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChristensen committed Mar 26, 2024
1 parent 2c0ed02 commit 05121e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -10,6 +10,8 @@ o FIX: bug in argument 'returnAllResults' for `EBICglasso.qgraph`

o UPDATE: `network.predictability` uses empirical inverse variances (rather than network-implied)

o UPDATE: R-squared in `continuous_accuracy` helper uses formula for no intercept


Changes in version 2.0.5

Expand Down
14 changes: 6 additions & 8 deletions R/helpers.R
Expand Up @@ -2870,21 +2870,19 @@ pcor2inv <- function(partial_correlations)

#' @noRd
# Continuous Accuracy (for single variable) ----
# Updated 12.02.2024
# Updated 26.03.2024
continuous_accuracy <- function(prediction, observed)
{

# Compute square error
square_error <- (prediction - observed)^2
# No intercept for prediction
# sum((observed - mean(observed, na.rm = TRUE))^2, na.rm = TRUE)
# A great explanation on why not: https://stats.stackexchange.com/questions/26176/removal-of-statistically-significant-intercept-term-increases-r2-in-linear-mo

# Return accuracies
return(
c(
R2 = 1 - (
sum(square_error, na.rm = TRUE) /
sum((observed - mean(observed, na.rm = TRUE))^2, na.rm = TRUE)
),
RMSE = sqrt(mean(square_error, na.rm = TRUE))
R2 = sum(prediction^2, na.rm = TRUE) / sum(observed^2, na.rm = TRUE),
RMSE = sqrt(mean((prediction - observed)^2, na.rm = TRUE))
)
)

Expand Down

0 comments on commit 05121e8

Please sign in to comment.