0

The code below produces an ANOVA summary table:

anova_weather_score = ezANOVA(weather_summary, dv = .(Score), wid = .(SubjectID), within =          .(Backlight, TargetColor), between = .(ColorVision), detailed = TRUE)
Mn = mean(weather_summary$Score)
SST = sum((weather_summary$Score - Mn)^2)
print(anova_weather_score)

The output is formatted nicely, like this:

## $ANOVA
##                              Effect DFn DFd          SSn      SSd            F
## 1                       (Intercept)   1  28 3553270.4678 51610.00 1927.7575933
## 2                       ColorVision   1  28    7420.9029 51610.00    4.0260662
## 3                         Backlight   5 140  153757.6569 39660.61  108.5514016
## 5                       TargetColor   2  56  102265.9725 22160.61  129.2133602
## 4             ColorVision:Backlight   5 140    3812.9949 39660.61    2.6919371
## 6           ColorVision:TargetColor   2  56     389.8112 22160.61    0.4925276
## 7             Backlight:TargetColor  10 280   57694.3679 65001.57   24.8523578
## 8 ColorVision:Backlight:TargetColor  10 280    2578.6755 65001.57    1.1107872

But if I use paste0 to try to append the total sum of squares to the output, the paste works but the formatting is ruined, i.e.:

anova_weather_score = ezANOVA(weather_summary, dv = .(Score), wid = .(SubjectID), within = .(Backlight, TargetColor), between = .(ColorVision), detailed = TRUE)
Mn = mean(weather_summary$Score)
SST = sum((weather_summary$Score - Mn)^2)
anova_weather_score = paste0(anova_weather_score, "SST = ", SST)
print(anova_weather_score)

The output looks like this:

[1] "list(Effect = c(\"(Intercept)\", \"ColorVision\", \"Backlight\", \"TargetColor\", \"ColorVision:Backlight\", \"ColorVision:TargetColor\", \"Backlight:TargetColor\", \"ColorVision:Backlight:TargetColor\"), DFn = c(1, 1, 5, 2, 5, 2, 10, 10), DFd = c(28, 28, 140, 56, 140, 56, 280, 280), SSn = c(3553270.46777402, 7420.90293309264,

and ends with:

\"\", \"*\", \"\"))SST = 506353.173845225"

How can I append SST to the table without disturbing its formatting?

Dave
  • 1
  • 2
  • What is your expected output? If you just want to add an element to the list, do `rt_anova$SST <- SST`. If you want to add a column to `$ANOVA` and repeat the same SST value in each row, `rt_anova$ANOVA |> dplyr::mutate(SST = 12345)` – andrew_reece Mar 09 '23 at 02:02
  • Ultimately, I'd like to add a column labeled "R2" that shows the value of SSn / SST for each effect that yields p < 0.1 (where the values of SSn come from the summary table). I thought I'd start with the more modest goal of appending SST without spoiling the formatting. Your 2nd example may be enough of a pointer for me to work the rest out -- thanks! – Dave Mar 09 '23 at 02:50
  • 2
    You're welcome. FWIW it'd be a lot easier to help with a precise solution if you provide a reproducible example and expected output. – andrew_reece Mar 09 '23 at 03:35
  • I thought I did. I showed a section of code and an example of its output. Then, I showed the modified code and an example of its undesirable output for comparison. The problem would occur with any data file, so I thought the problem should be reproducible. What else or more should I have included? – Dave Mar 09 '23 at 17:42
  • Have a look at [How to make a great reproducible R example](https://stackoverflow.com/a/5963610/2799941). Without (1) runnable code (which includes example data) that exactly reproduces your issue, and (2) clear representation of expected/desired output, it makes it a lot harder to help solve your problem. – andrew_reece Mar 09 '23 at 18:02
  • I read that guidance and understand that some problems require providing an executable example that errors so others can help debug it. The 2 problems I've posted so far are "R virgin who's tasked with expanding someone else's code without having time to study R properly" type. My blunders tend to be due to fundamental ignorance, so they're obvious to knowledgeable people merely from seeing the code (as you found). I hope to graduate to problems more worthy of this forum ASAP! :) Meanwhile, thanks again for your help and guidance. – Dave Mar 10 '23 at 20:03

0 Answers0