Learn R Programming

preText (version 0.6.2)

calculate_prediction_errors: Calculate mean prediction error for preprocessing decisions.

Description

Use scaled positions to predict preprocessing decisions.

Usage

calculate_prediction_errors(positions_list, preprocessing_choices)

Arguments

positions_list

A list of scaled document positions generated by the `scaling_comparison()` functions and returned from that function in the `$scaled_positions` slot in the list object.

preprocessing_choices

A data frame containing binary indicators of whether each preprocessing decision was applied for each dfm. This is returned by the `factorial_preprocessing()` function as part of its output.

Value

A vector of mean prediction errors.

Examples

Run this code
# NOT RUN {
# *** This function is used automatically inside of the preText() function.
# load the package
library(preText)
# load in the data
data("UK_Manifestos")
# preprocess data
preprocessed_documents <- factorial_preprocessing(
    UK_Manifestos,
    use_ngrams = TRUE,
    infrequent_term_threshold = 0.02,
    verbose = TRUE)
# scale documents
scaling_results <- scaling_comparison(preprocessed_documents$dfm_list,
                                      dimensions = 2,
                                      distance_method = "cosine",
                                      verbose = TRUE)
# get prediction errors
pred_errors <- calculate_prediction_errors(
     scaling_results$scaled_positions,
     preprocessed_documents$choices)
# }

Run the code above in your browser using DataLab