Association Between a Continuous Response and a Continuous Predictor
Source:R/preference_order_methods.R
f_r2.Rd
These functions take a data frame with two numeric continuous columns "x" (predictor) and "y" (response), fit a univariate model, and return the R-squared of the observations versus the model predictions:
f_r2_pearson()
: Pearson's R-squared.f_r2_spearman()
: Spearman's R-squared.f_r2_glm_gaussian()
: Pearson's R-squared of a GLM model fitted withstats::glm()
, with formulay ~ s(x)
and familystats::gaussian(link = "identity")
.f_r2_glm_gaussian_poly2()
: Pearson's R-squared of a GLM model fitted withstats::glm()
, with formulay ~ stats::poly(x, degree = 2, raw = TRUE)
and familystats::gaussian(link = "identity")
.f_r2_gam_gaussian()
: Pearson's R-squared of a GAM model fitted withmgcv::gam()
, with formulay ~ s(x)
and familystats::gaussian(link = "identity")
.f_r2_rpart()
: Pearson's R-squared of a Recursive Partition Tree fitted withrpart::rpart()
with formulay ~ x
.f_r2_rf()
: Pearson's R-squared of a 100 trees Random Forest model fitted withranger::ranger()
and formulay ~ x
.
Usage
f_r2_pearson(df)
f_r2_spearman(df)
f_r2_glm_gaussian(df)
f_r2_glm_gaussian_poly2(df)
f_r2_gam_gaussian(df)
f_r2_rpart(df)
f_r2_rf(df)
See also
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Other preference_order_functions:
f_auc
,
f_r2_counts
,
f_v()
,
f_v_rf_categorical()
Examples
data(vi)
#reduce size to speed-up example
vi <- vi[1:1000, ]
#numeric response and predictor
#to data frame without NAs
df <- data.frame(
y = vi[["vi_numeric"]],
x = vi[["swi_max"]]
) |>
na.omit()
# Continuous response
#Pearson R-squared
f_r2_pearson(df = df)
#> [1] 0.5933516
#Spearman R-squared
f_r2_spearman(df = df)
#> [1] 0.4532391
#R-squared of a gaussian gam
f_r2_glm_gaussian(df = df)
#> [1] 0.5933516
#gaussian glm with second-degree polynomials
f_r2_glm_gaussian_poly2(df = df)
#> [1] 0.6007664
#R-squared of a gaussian gam
f_r2_gam_gaussian(df = df)
#> [1] 0.6704248
#recursive partition tree
f_r2_rpart(df = df)
#> [1] 0.6543777
#random forest model
f_r2_rf(df = df)
#> [1] 0.7279192
#load example data
data(vi)
#reduce size to speed-up example
vi <- vi[1:1000, ]
#continuous response and predictor
#to data frame without NAs
df <- data.frame(
y = vi[["vi_numeric"]],
x = vi[["swi_max"]]
) |>
na.omit()
# Continuous response
#Pearson R-squared
f_r2_pearson(df = df)
#> [1] 0.5933516
#Spearman R-squared
f_r2_spearman(df = df)
#> [1] 0.4532391
#R-squared of a gaussian gam
f_r2_glm_gaussian(df = df)
#> [1] 0.5933516
#gaussian glm with second-degree polynomials
f_r2_glm_gaussian_poly2(df = df)
#> [1] 0.6007664
#R-squared of a gaussian gam
f_r2_gam_gaussian(df = df)
#> [1] 0.6704248
#recursive partition tree
f_r2_rpart(df = df)
#> [1] 0.6543777
#random forest model
f_r2_rf(df = df)
#> [1] 0.7279192