Skip to contents

Compute the mean of central estimates or the focal predictor

Usage

# S3 method for varpred
getmeans(
  object,
  what = c("both", "estimate", "focal"),
  focal = NULL,
  modelname = NULL
)

Arguments

object

varpred object.

what

a character specifying what mean to compute. If "estimate", the mean of the central estimate is computed, if "focal" the mean of the focal predictor, otherwise, both are computed.

focal

a character specifying the name of focal predictor. If NULL (default), x.var from the object is used.

modelname

character string naming varpred objects. Useful when comparing several objects.

Value

a data frame.

Details

Provides a quick way to compare observed data marginal means with that of the central estimate. Current version ignores interactions and averages the fit column only.

Examples

library(varpred)
library(ggplot2)
## Set theme for plots
varpredtheme()
## Fit the model
mod <- lm(mpg ~ wt + hp, mtcars)
## Effect
ef <- varpred(mod, "wt")
head(ef, 3)
#>         wt      fit        se      lwr      upr
#> 1 1.513000 26.68754 1.0763972 24.48606 28.88902
#> 2 1.638571 26.19960 0.9967831 24.16095 28.23825
#> 3 1.856429 25.35308 0.8586584 23.59693 27.10923
tail(ef, 3)
#>          wt      fit           se       lwr      upr
#> 27 5.334821 11.83714 1.346695e+00  9.082844 14.59144
#> 28 5.424000 11.49062 1.403235e+00  8.620686 14.36056
#> 29 3.210747 20.09062 1.404951e-15 20.090625 20.09063

## Compute means of the predictions
ef_m <- getmeans(ef, what="both", modelname="estimated")
print(ef_m)
#>         wt      fit     model
#> 1 3.210747 20.09062 estimated
# Data mean
mpg_m <- mean(mtcars$mpg)
print(mpg_m)
#> [1] 20.09062