I am analysing fishing surveys using the survey package. My PSU is the person and I want to obtain estimates of the proportion of successful fishing trips. Each person has a variable number of fishing trips (trials) and successes.
I can use svyratio() to calc p.hat = mean(successes)/mean(trials) or I can calculate p.i for each person as #succesess/#trials and use svymean() to get p.hat = mean(p.i)
For both approaches the SE calculation uses the #Persons (replicates/PSU’s), not the total number of trials. I’m wondering if this matters?
Of the two approaches, I would prefer to use the latter approach (where p.hat = mean(p.i)), as this is what has been used on a different (non-survey) data set. However, do I need to calculate an alternative se to that obtained via svymean()? And if so, is it just:
p <- svymean(~Pi, s)[[1]]
se.p <- sqrt(p *(1- p)/N))
? Thank you
Example data/code:
d <- data.frame(cbind(NTrips=round(runif(50, min=1, max=50),0), p=runif(50, min=0, max=1),
weights=rnorm(50,1000,500)))
d <- cbind(Person=paste("P",seq(1:50),sep="_"),d)
d$NSuccess <- d$NTrips*d$p
d$PropST <-d$NSuccess/d$NTrips
library(survey)
s <- svydesign(~1,data=d, weights=~weights)
N <- nrow(d) # total number of replicates/PSUs
(pr <- svyratio(~NSuccess,~NTrips,s))
(se.pr <- sqrt(pr[[1]] *(1- pr[[1]])/N))
(pm <- (svymean(~PropST, s)))
(se.pm <- sqrt(pm[[1]] *(1- pm[[1]])/N))