Learn R Programming

filtro (version 0.2.0)

score_aov_pval: Scoring via analysis of variance hypothesis tests

Description

These two objects can be used to compute importance scores based on Analysis of Variance techniques.

Usage

score_aov_pval

score_aov_fstat

Arguments

Value

An S7 object. The primary property of interest is in results. This is a data frame of results that is populated by the fit() method and has columns:

  • name: The name of the score (e.g., aov_fstat or aov_pval).

  • score: The estimates for each predictor.

  • outcome: The name of the outcome column.

  • predictor: The names of the predictor inputs.

These data are accessed using object@results (see examples below).

Format

An object of class filtro::class_score_aov (inherits from filtro::class_score, S7_object) of length 1.

An object of class filtro::class_score_aov (inherits from filtro::class_score, S7_object) of length 1.

Details

These objects are used when either:

  • The predictors are numeric and the outcome is a factor/category, or

  • The predictors are factors and the outcome is numeric.

In either case, a linear model (via stats::lm()) is created with the proper variable roles, and the overall p-value for the hypothesis that all means are equal is computed via the standard F-statistic. The p-value that is returned is transformed to be -log10(p_value) so that larger values are associated with more important predictors.

Estimating the scores

In filtro, the score_* objects define a scoring method (e.g., data input requirements, package dependencies, etc). To compute the scores for a specific data set, the fit() method is used. The main arguments for these functions are:

object

A score class object (e.g., score_aov_pval).

formula

A standard R formula with a single outcome on the right-hand side and one or more predictors (or .) on the left-hand side. The data are processed via stats::model.frame()

data

A data frame containing the relevant columns defined by the formula.

...

Further arguments passed to or from other methods.

case_weights

A quantitative vector of case weights that is the same length as the number of rows in data. The default of NULL indicates that there are no case weights.

Missing values are removed for each predictor/outcome combination being scored.

In cases where the underlying computations fail, the scoring proceeds silently, and a missing value is given for the score.

See Also

Other class score metrics: score_cor_pearson, score_imp_rf, score_info_gain, score_roc_auc, score_xtab_pval_chisq

Examples

Run this code
# Analysis of variance where `class` is the class predictor and the numeric
# predictors are the outcomes/responses

cell_data <- modeldata::cells
cell_data$case <- NULL

# ANOVA p-value
cell_p_val_res <-
  score_aov_pval |>
  fit(class ~ ., data = cell_data)
cell_p_val_res@results

# ANOVA raw p-value
natrual_units <- score_aov_pval |> dont_log_pvalues()
cell_pval_natrual_res <-
  natrual_units |>
  fit(class ~ ., data = cell_data)
cell_pval_natrual_res@results

# ANOVA t/F-statistic
cell_t_stat_res <-
  score_aov_fstat |>
  fit(class ~ ., data = cell_data)
cell_t_stat_res@results

# ---------------------------------------------------------------------------
library(dplyr)

# Analysis of variance where `chem_fp_*` are the class predictors and
# `permeability` is the numeric outcome/response

permeability <-
  modeldata::permeability_qsar |>
  # Make the problem a little smaller for time; use 50 predictors
  select(1:51) |>
  # Make the binary predictor columns into factors
  mutate(across(starts_with("chem_fp"), as.factor))

perm_p_val_res <-
  score_aov_pval |>
  fit(permeability ~ ., data = permeability)
perm_p_val_res@results

# Note that some `lm()` calls failed and are given NA score values. For
# example:
table(permeability$chem_fp_0007)

perm_t_stat_res <-
  score_aov_fstat |>
  fit(permeability ~ ., data = permeability)
perm_t_stat_res@results

Run the code above in your browser using DataLab