DistanceDevelopment / mrds

R package for mark-recapture-distance-sampling analysis
GNU General Public License v3.0
4 stars 4 forks source link

Variance components table branch #76

Open erex opened 1 year ago

erex commented 1 year ago

Trying to assess variance components table added to dht in this branch.

Note the data issue has been resolved, see next comment

songbirds.csv

birds <- read.csv("E:/Troubleshoot/Arapaho/songbirds.csv", header=TRUE)
birds80 <- birds[birds$Year==1980, ]
table(birds$species, birds$Region.Label)
regtab <- data.frame(Region.Label=unique(birds80$Region.Label),
                     Area=rep(1,3))
p1.stns <- c(seq(1:110), seq(112, 122, by=2), seq(150, 156, by=2))
p2.stns <- seq(1:125)
p3.stns <- c(seq(1:4), seq(6, 25, by=1), seq(27, 125, by=1))
samtab <- data.frame(Sample.Label=c(p1.stns, p2.stns, p3.stns) ,
                     Region.Label=c(rep("1980_1", length(p1.stns)),
                                    rep("1980_2", length(p2.stns)),
                                    rep("1980_3", length(p3.stns))) ,
                     Effort=1)
obstab <- data.frame(object=birds80$Observation,
                     Region.Label=birds80$Region.Label,
                     Sample.Label=birds80$Sample.Label)
cu <- convert_units("meter", NULL, "hectare")
sasp <- birds80[birds80$species=='SASP', ]
# obstab <- data.frame(object=sasp$Observation,
#                      Region.Label=sasp$Region.Label,
#                      Sample.Label=sasp$Sample.Label)

hncos <- ds(sasp, key="hn", transect="point",
            convert_units = cu,
            region_table = regtab, sample_table = samtab,
            obs_table = obstab)
erex commented 1 year ago

Checking variance component table computation using Savannah Sparrow 1980 data.

Results from DistWin

Stratum 1 Component Percentages of Var(D) Detection probability : 15.9 Encounter rate : 81.0 Cluster size : 3.1

Stratum 2 Component Percentages of Var(D) Detection probability : 28.1 Encounter rate : 66.1 Cluster size : 5.8

Stratum 3 Component Percentages of Var(D) Detection probability : 30.4 Encounter rate : 61.8 Cluster size : 7.8

Results from Distance package

mrds * 2.2.8.9003 2023-02-01 [1] Github (DistanceDevelopment/mrds@906a1ff)

Variance contributions Region ER Detection 1 1980_1 80.74720 19.25280 2 1980_2 66.81556 33.18444 3 1980_3 66.02137 33.97863 4 Total 44.97079 55.02921

Conclusion

Variance component table produced by mrds seems unaware of group size in this data set. The contribution attributable to encounter rate variability is roughly correct (except stratum 3) and both detection function uncertainty and group size variability is combined into component called "Detection".

Minimum Reproducible Example

Songbird csv file linked to previous comment, with this simplified analysis code

library(Distance)
birds <- read.csv("E:/Troubleshoot/Arapaho/songbirds.csv", header=TRUE)
birds80 <- birds[birds$Year==1980, ]
table(birds$species, birds$Region.Label)
regtab <- data.frame(Region.Label=unique(birds80$Region.Label),
                     Area=rep(1,3))
p1.stns <- c(seq(1:110), seq(112, 122, by=2), seq(150, 156, by=2))
p2.stns <- seq(1:125)
p3.stns <- c(seq(1:4), seq(6, 25, by=1), seq(27, 125, by=1))
samtab <- data.frame(Sample.Label= c(p1.stns, p2.stns, p3.stns),
                     Region.Label=c(rep("1980_1", length(p1.stns)),
                                    rep("1980_2", length(p2.stns)),
                                    rep("1980_3", length(p3.stns))) ,
                     Effort=1)
cu <- convert_units("meter", NULL, "hectare")
sasp <- birds80[birds80$species=='SASP', ]
hncos3 <- ds(sasp, key="hn", transect="point",
            convert_units = cu, 
            region_table = regtab, sample_table = samtab) 
print(hncos3$dht) # only with print statement is component table produced