Search code examples
rinterpretationeffects

What is "fit" in the data.frame command within the effects package in R?


When running the data.frame command in R (shown below - please note that "Macro" is my variable of interest within the model), I get an output for my variable, fit, se, lower, and upper. I am aware of what each output is telling me except fit.

> data.frame(effect(c("Macro"), model))
    Macro   fit        se         lower      upper
  1     C   45.30041   5.650558   34.14164   56.45918
  2     R   33.73317   4.394917   25.05406   42.41229

When I run the effect command (which I originally thought was giving me my standard deviation) I get the same numbers as fit:

> effect(c("macro"), model)
   Macro effect
   Macro
          C          R
   45.30041   33.73317

Is this truly the standard deviation, or is fit more representative of the mean? And, of course, there is always the option that I am completely off base with both of these potential interpretations.


Solution

  • fit represents your fitted or predicted values given your regression model. In your case with categorical predictors, it's the mean:

    library(effects) ## to access the effect() function
    
    m1 <- lm(weight ~ group, data = PlantGrowth)
    
    data.frame(effect(c("group"), m1))
      group   fit        se    lower    upper
    1  ctrl 5.032 0.1971284 4.627526 5.436474
    2  trt1 4.661 0.1971284 4.256526 5.065474
    3  trt2 5.526 0.1971284 5.121526 5.930474
    
    # CALCULATE MEANS
    aggregate(weight ~ group, data = PlantGrowth, mean)
      group weight
    1  ctrl  5.032
    2  trt1  4.661
    3  trt2  5.526
    

    Not sure why you thought that effect() will give you the standard deviation. Have a look at ?effect to see what you will get when using the function.