Laura,
The survey package is the standard in R for survey analysis. Here is a simple example using example data:
library(survey)
data(api)
# stratified sample
dstrat <- svydesign(
id = ~ 1,
strata = ~ stype,
weights = ~ pw,
data = apistrat)
dstrat
svymean(~ api99, dstrat) # Stratified mean
svyby(~ api99, by = ~ stype, dstrat, FUN = svymean) # Stratified mean by subsets - your subsets could be year if appropriate.
If the survey has a complex design in time (waves, panels, etc) then it may be easier to construct a separate "svydesign" object for each year. If your PSUs are the same for each year, then you can use separate variables for each year and use svymean( ~ year1 + year2 + year3, design).
HTH,
Jason Law
Statistician
City of Portland | Environmental Services
phone: 503-823-1038
-----Original Message-----
From: R-sig-ecology <r-sig-ecology-bounces at r-project.org> On Behalf Of Lee, Laura
Sent: Friday, September 9, 2022 9:53 AM
To: r-sig-ecology at r-project.org
Subject: [R-sig-eco] Calculating annual stratified means
Hey all,
I'm wondering what is the simplest package for calculating an annual stratified mean? I have raw survey data that includes counts of fish by date and stratum. I also have the stratum weights. Sample code would also be appreciated!
Thanks so much!
Best fishes,
Laura
Laura M. Lee
Stock Assessment Program Manager
Division of Marine Fisheries
Department of Environmental Quality
252 808 8072??? office
Laura.Lee at ncdenr.gov
3441 Arendell Street
P.O. Box 769
Morehead City, NC 28557-0769
Email correspondence to and from this address is subject to the North Carolina Public Records Law and may be disclosed to third parties.
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology