0

My summarySE output looks like this:

summary <- summarySE(df, measurevar = "Cover", groupvars = c("Year","Loc")) 

  Year   Loc N     Cover      sd         se         ci
1 2010    1 104 0.10560533 0.2163059 0.02121054 0.04206610
2 2010    2  97 0.06513590 0.1505460 0.01528563 0.03034173
3 2010    3  48 0.12428977 0.2031627 0.02932401 0.05899230
4 2011    1  90 0.09785354 0.2184823 0.02303006 0.04576023
5 2011    2  88 0.04467975 0.1591636 0.01696690 0.03372355
6 2011    3  45 0.06313131 0.1494173 0.02227382 0.04488992

The problem is, because of the layout of my data frame I have had to include multiple rows for the same quadrat that I used during sampling, due to multiple species occupying the same quadrat.

E.g.

Quadrat_no. Year Site Cover
    1       2010   1    10
    2       2010   1     5
    2       2010   1     6
    3       2010   1     7  etc.

Therefore, R is summing all the values in Cover, and dividing it by (e.g. 104) to calculate the weighted mean (e.g. 0.105), rather than the true sample size.

Is it possible to change my dataframe, so that R recognises that multiple rows represent a single quadrat? Therefore, changing N seen in summarySE.

Edit: I have since found on: https://cran.r-project.org/web/packages/Hmisc/Hmisc.pdf that I may be able to use normwt, although I can't figure out how to implement it, since there are no examples.

  • What package is `summarySE` from? Maye you should just use `data.table` or `dplyr` so you have full control over your grouping and calculations – Gregor Thomas Jan 15 '18 at 22:23
  • `summarySE` is from the package `RMisc`. – Charlie Jones Jan 15 '18 at 22:25
  • I think you would have to specify what you want to do with `Cover` as you combine rows - should it be added, averaged, weighted average based on N, multiplied, something else? – Gregor Thomas Jan 15 '18 at 22:46
  • That's exactly it, I plan on calculating a weighted average based on N. – Charlie Jones Jan 15 '18 at 22:48
  • `summarySE` doesn't seem to have any weighting implemented, nor do I know of an easy way to get weighted standard errors. I'm still a bit unclear as to your input data structure and exactly which columns need averaging (I see `N` in the summarySE output, but not in your sample data??) If you can make your example clearer, we can try to work something out. But really you might just want to take a look at the [mean by group R-FAQ](https://stackoverflow.com/q/11562656/903061) and find a method there that you like. You can always replace `mean()` by `weighted.mean()`. – Gregor Thomas Jan 16 '18 at 01:54

0 Answers0