Skip to contents

This function takes a data frame, performs linear regression on specified grouping variables, and computes R-squared values for each group.

Usage

compute_rsquare(data, grouping_by = c("from", "description"))

Arguments

data

A data frame containing the variables 'actual' and 'estimate' for regression.

grouping_by

A character vector specifying the grouping variables for regression.

Value

A data frame with columns 'from', 'term', and 'R2' representing the grouping variables and the corresponding R-squared values.

Examples

data <- data.frame(from = c("A", "A", "A", "A"),
                   term = c("X", "Y", "X", "Y"),
                   actual = c(1, 2, 3, 4),
                   estimate = c(1.5, 2.5, 3.5, 4.5))
compute_rsquare(data, grouping_by = c("from", "term"))
#>   from term R2
#> 1    A    X  1
#> 2    A    Y  1