3
$\begingroup$

I have angler catch data from tournaments over 10 years and want to compare the proportion of each species (Sp1 vs. Sp2, Sp1 vs. Sp3, Sp2 vs. Sp3) caught within each year 2005 to 2015. So were more of Sp1 caught than Sp2 during year 2005, 2006,...2015. I've been able to do this with a linear model an a Tukey test but I want to make sure this is the correct way to go since the aov() test gives a warning (Estimated effects may be unbalanced). I have the same number of data points for each species but different number of tournaments each year. However, the amount of effort for each tournament does vary. I tried fitting a generalized linear model with an off set for effort and a negative binomial distribution but could not get it to work. I'm not particularly familiar with glm() and also don't know if there is a tukey test for a glm() model.

Questions:

  1. do I need to use a glm() to compare proportion of each species caught within each year or is the linear model acceptable?
  2. is there a tukey test for glm() models?

My code and data are below

Proportion of angler catch for 3 species

Setting up aov() test

aov(catch ~ factor(year):species,
                      data = sim_dat)

Gives warning Estimated effects may be unbalanced

Running Tukey test

aov(catch ~ factor(year):species,
                  data = sim_dat) %>%
  TukeyHSD()

When trying to fit the glm() I first fit a linear model to get starting values. Not sure this is the best way to go but I don't know how else to go about it.

lm1 <- lm(catch ~ factor(year):species,
    data = sim_dat) 

summary(lm1)
coef(lm1)

starts <- coef(lm1) %>%
  as.vector() %>%
  subset( !(is.na(.)))

starts <- c(starts,0)
starts

glm(catch ~ factor(year):species,
    data = sim_dat,
    family = nb(link = "log"),
    offset = log(eff_hrs),
    start = starts)

Gives error Error in mu + Theta : non-numeric argument to binary operator In addition: Warning message: glm.fit: algorithm did not converge

Here is my data

sim_dat <- structure(list(year = c(2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2006L, 2006L, 2006L, 
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 
2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 
2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 
2014L, 2014L, 2014L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 
2015L, 2015L, 2015L, 2015L, 2015L, 2015L), eff_hrs = c(162, 162, 
162, 468, 468, 468, 468, 468, 468, 559, 559, 559, 774, 774, 774, 
180, 180, 180, 1406, 1400, 1404, 1407, 1404, 1404, 400, 400, 
400, 352, 352, 352, 99, 99, 99, 288, 292, 288, 162, 162, 162, 
216, 216, 216, 288, 288, 292, 324, 324, 324, 1296, 1296, 1296, 
304, 304, 304, 1156, 1156, 1156, 994, 992, 993, 292, 288, 288, 
1216, 1216, 1212, 256, 256, 256, 243, 243, 243, 1116, 1116, 1113, 
936, 936, 936, 1071, 1071, 1074, 1071, 1072, 1071, 48, 48, 48, 
275, 270, 270, 48, 48, 48, 234, 234, 236, 286, 286, 286, 144, 
144, 141, 1063, 1062, 1062, 35, 32, 32, 112, 112, 112, 765, 765, 
765, 761, 765, 765, 293, 293, 297, 60, 56, 57, 50, 48, 48, 698, 
697, 706, 702, 702, 698, 235, 235, 235, 216, 216, 221, 40, 40, 
40, 70, 70, 70, 153, 153, 153, 99, 99, 99, 39, 40, 40, 292, 296, 
301, 972, 972, 968, 62, 64, 64, 36, 36, 36, 80, 77, 80, 328, 
328, 328, 92, 90, 91, 904, 904, 904, 225, 225, 221, 1206, 1211, 
1206, 1072, 1072, 1072, 306, 306, 306, 1103, 1098, 1098, 1098, 
1098, 1098, 324, 324, 324, 1782, 1780, 1782, 1566, 1568, 1568, 
16, 14, 16, 432, 432, 432, 220, 220, 220, 56, 56, 56, 56, 56, 
56, 432, 433, 432, 17.5, 17.5, 17.5, 678, 680, 680, 595, 595, 
598, 10.5, 10.5, 10.5, 756, 756, 756, 756, 759, 761, 200, 200, 
200, 15, 14, 14, 270, 270, 270, 38.5, 41.5, 42.5, 653, 648, 648, 
808, 813, 808, 688, 688, 688, 333, 333, 333, 131, 135, 135, 130, 
124, 122, 414, 414, 414, 30, 30, 30, 51, 48, 49, 117, 118, 117, 
952, 952, 950, 954, 954, 954, 48, 53, 48, 2290, 2290, 2290, 2000, 
1998, 1997, 152, 152, 149, 144, 144, 144, 174, 174, 176, 326, 
324, 329, 351, 350, 355, 32, 32, 32, 252, 249, 256, 736, 736, 
736, 288, 288, 288, 342, 342, 342, 112, 112, 112, 864, 864, 864, 
972, 972, 967, 864, 861, 864, 699, 704, 704, 705, 704, 704, 704, 
704, 704, 95, 99, 99, 247, 252, 252, 1006, 1008, 1012, 344, 348, 
344, 265, 270, 273, 1098, 1098, 1098, 100, 96, 96, 526, 522, 
522, 1224, 1226, 1224, 88, 88, 88, 2232, 2232, 2232, 1984, 1984, 
1981, 142, 144, 144, 396, 396, 396, 653, 653, 653, 161, 161, 
161, 36, 32, 36, 144, 144, 144, 133, 135, 135, 414, 414, 414, 
270, 270, 270, 135, 135, 135, 48, 48, 48, 670, 667, 666, 199, 
198, 201, 117, 117, 120, 339, 342, 342, 576, 576, 576, 135, 135, 
135, 387, 387, 387, 1152, 1155, 1152, 1024, 1024, 1024, 73, 72, 
72, 175, 176, 176, 918, 918, 918, 234, 234, 234, 60, 64, 64, 
2253, 2250, 2253, 1996, 2000, 2003, 108, 108, 108, 80, 77, 80, 
848, 846, 846, 144, 144, 144, 423, 423, 423, 85, 90, 90, 48, 
51, 48, 348, 351, 348, 72, 72, 72, 117, 118, 117, 636, 636, 639, 
936, 936, 940, 832, 830, 832, 880, 880, 882, 269, 270, 271, 72, 
72, 72, 80, 80, 80, 346, 342, 342, 944, 944, 944, 56, 52, 52, 
244, 240, 240, 240, 235, 240, 828, 826, 828, 459, 459, 459, 80, 
80, 81, 900, 898, 900, 55, 56, 52, 2250, 2250, 2250, 2250, 2250, 
2250, 468, 468, 468, 417, 414, 414, 203, 200, 200, 684, 684, 
681, 698, 702, 702, 468, 465, 468, 69, 72, 72, 42, 42, 42, 324, 
329, 324, 333, 333, 333, 558, 558, 558, 48, 48, 48, 288, 288, 
288, 749, 748, 744, 648, 648, 648, 54, 54, 50, 331, 328, 328, 
80, 81, 80, 364, 360, 360, 360, 360, 360, 80, 80, 80, 846, 841, 
846, 1022, 1022, 1022, 752, 752, 752, 584, 588, 582, 378, 378, 
378, 180, 180, 180, 243, 243, 243, 108, 108, 108, 225, 225, 225, 
1040, 1040, 1040, 90, 90, 90, 291, 288, 288, 90, 90, 88, 20, 
20, 20, 110, 112, 110, 20, 16, 20, 40, 40, 40, 104, 104, 104, 
29, 24, 24, 874, 874, 874, 384, 384, 384, 784, 784, 784, 24, 
24, 22, 76, 75, 74, 792, 792, 794, 856, 856, 857, 49.5, 49.5, 
49.5, 70, 70, 70, 2436, 2429, 2432, 565, 560, 560, 2429, 2435, 
2432, 45, 45, 45, 87, 90, 90, 81, 81, 81, 234, 234, 234, 49.5, 
49.5, 49.5, 288, 288, 288, 55, 60, 60, 113, 114, 114, 450, 450, 
450, 39, 36, 36, 50, 50, 50, 644, 648, 648, 49.5, 46.5, 49.5, 
450, 446, 450, 72, 72, 72, 70, 70, 70, 208, 208, 208, 67.5, 66.5, 
67.5, 112, 112, 112, 76.5, 76.5, 76.5, 192, 192, 192, 361, 360, 
360, 108, 108, 108, 40, 40, 36, 96, 96, 96, 126, 126, 126, 65, 
65, 65, 1008, 1008, 1008, 90, 90, 90, 155, 147, 151, 382, 379, 
378, 76, 80, 80, 75, 75, 77, 48, 48, 47, 55, 60, 52, 554, 558, 
558, 68, 68, 72, 672, 672, 672, 672, 672, 672, 672, 673, 673, 
176, 176, 180, 268, 264, 264, 35, 33, 35, 816, 816, 816, 90, 
90, 90, 34, 35, 35, 72, 75, 72, 306, 307, 306, 39, 39, 40, 408, 
408, 411, 275, 272, 267, 176, 176, 174, 376, 376, 375, 704, 704, 
704, 62, 64, 64, 100, 104, 103, 1080, 1080, 1076, 960, 960, 965, 
288, 285, 288, 320, 320, 320, 904, 904, 904, 198, 199, 198, 52, 
52, 52, 1144, 1146, 1144, 44, 44, 44, 445, 448, 448, 368, 371, 
371, 545, 549, 549, 48, 48, 48, 52, 52, 52, 126, 128, 133, 2340, 
2340, 2340, 2337, 2340, 2345, 32, 28, 32, 96, 96, 97, 180, 180, 
180, 32, 33, 32, 648, 648, 644, 36, 35, 36, 216, 216, 216, 40, 
40, 45, 36, 36, 36, 32, 35, 32, 29, 28, 28, 824, 824, 824, 28, 
28, 27, 504, 504, 504, 1008, 1008, 1008, 896, 899, 896, 31.5, 
31.5, 31.5, 702, 700, 702, 159, 162, 162, 943.5, 943.5, 940.5, 
624, 624, 624, 232, 234, 232, 800, 800, 802, 64, 64, 65, 29, 
32, 32, 52, 48, 48, 46, 48, 51, 558, 558, 558, 48, 51, 48, 37, 
38, 40, 288, 288, 288, 27, 24, 22, 32, 32, 32, 738, 738, 735, 
64, 59, 64, 56, 56, 60, 597, 602, 602, 54, 57, 52, 136, 136, 
136, 1296, 1299, 1296, 736, 736, 736, 288, 288, 288, 601, 600, 
600, 285, 292, 288, 185, 180, 180, 288, 288, 288, 504, 504, 502, 
352, 352, 352, 810, 805, 812, 721, 720, 720, 560, 560, 560, 240, 
240, 243), catch = c(6, 7, 4, 33, 8, 9, 14, 3, 5, 6, 14, 4, 5, 
19, 11, 9, 2, 0, 56, 22, 15, 58, 19, 16, 7, 10, 0, 12, 5, 4, 
6, 3, 3, 5, 11, 3, 8, 9, 8, 12, 15, 7, 14, 12, 12, 11, 14, 9, 
20, 58, 59, 34, 2, 51, 96, 33, 52, 58, 85, 26, 26, 19, 28, 16, 
75, 24, 17, 41, 17, 22, 42, 19, 33, 100, 25, 26, 29, 5, 9, 72, 
25, 9, 73, 25, 6, 3, 4, 20, 12, 8, 0, 2, 0, 16, 7, 10, 14, 0, 
13, 2, 1, 3, 49, 17, 21, 2, 3, 1, 2, 3, 0, 48, 21, 17, 17, 6, 
6, 4, 0, 5, 2, 3, 2, 2, 4, 3, 19, 9, 4, 7, 5, 3, 12, 3, 4, 7, 
2, 3, 4, 3, 0, 1, 0, 0, 1, 3, 1, 6, 33, 2, 1, 10, 1, 4, 58, 12, 
38, 67, 19, 1, 7, 0, 1, 6, 1, 2, 5, 0, 17, 21, 12, 10, 11, 9, 
74, 59, 83, 18, 13, 22, 68, 79, 54, 58, 53, 37, 15, 31, 12, 147, 
28, 11, 25, 201, 47, 31, 45, 18, 139, 174, 105, 117, 127, 53, 
0, 6, 0, 29, 61, 22, 19, 22, 12, 1, 10, 3, 2, 3, 2, 31, 12, 19, 
1, 0, 2, 12, 53, 21, 13, 45, 19, 0, 0, 1, 10, 45, 5, 14, 49, 
2, 2, 10, 1, 2, 0, 2, 7, 15, 12, 2, 1, 2, 28, 18, 18, 26, 58, 
30, 50, 9, 20, 12, 30, 25, 15, 0, 7, 3, 14, 7, 14, 41, 56, 1, 
5, 7, 15, 2, 8, 16, 8, 12, 63, 209, 17, 104, 79, 65, 3, 5, 5, 
164, 167, 171, 109, 121, 141, 0, 26, 7, 7, 14, 12, 8, 22, 18, 
33, 33, 22, 17, 18, 14, 0, 8, 3, 5, 38, 14, 19, 105, 32, 8, 34, 
12, 32, 34, 31, 6, 9, 0, 44, 89, 73, 51, 91, 43, 32, 64, 28, 
27, 98, 0, 16, 101, 0, 15, 105, 0, 1, 11, 3, 13, 17, 7, 34, 92, 
54, 1, 52, 6, 17, 30, 18, 184, 87, 24, 4, 20, 14, 47, 38, 31, 
28, 114, 68, 0, 22, 10, 71, 249, 32, 43, 202, 28, 2, 6, 6, 7, 
62, 21, 33, 36, 15, 5, 5, 2, 2, 2, 2, 4, 12, 4, 6, 10, 6, 8, 
19, 10, 5, 35, 4, 7, 4, 3, 0, 3, 0, 18, 36, 25, 3, 19, 1, 4, 
15, 12, 13, 53, 15, 5, 33, 53, 5, 18, 8, 3, 12, 4, 78, 87, 9, 
35, 77, 14, 6, 2, 1, 3, 12, 10, 17, 225, 8, 1, 74, 3, 1, 18, 
5, 171, 385, 70, 115, 230, 48, 10, 16, 12, 0, 31, 7, 32, 177, 
17, 13, 36, 3, 35, 59, 30, 7, 22, 4, 2, 17, 2, 0, 97, 2, 0, 13, 
2, 1, 26, 9, 7, 87, 18, 21, 336, 31, 17, 303, 26, 0, 230, 41, 
82, 0, 5, 1, 34, 3, 0, 20, 1, 7, 87, 16, 96, 123, 25, 0, 25, 
4, 3, 118, 2, 1, 114, 4, 32, 177, 41, 12, 119, 12, 0, 21, 7, 
45, 178, 40, 1, 19, 5, 155, 357, 63, 112, 274, 46, 14, 110, 13, 
5, 85, 5, 3, 49, 10, 54, 58, 9, 5, 70, 10, 7, 115, 11, 1, 8, 
1, 1, 0, 0, 11, 42, 9, 9, 60, 11, 21, 102, 14, 5, 19, 1, 9, 58, 
6, 34, 104, 20, 12, 124, 28, 0, 21, 0, 6, 67, 16, 2, 26, 20, 
10, 80, 16, 14, 72, 15, 2, 6, 6, 33, 194, 29, 12, 119, 101, 21, 
154, 23, 22, 62, 31, 10, 76, 17, 3, 36, 10, 4, 15, 6, 17, 0, 
1, 18, 24, 11, 52, 117, 21, 4, 17, 3, 1, 73, 12, 0, 29, 2, 0, 
13, 0, 0, 42, 4, 0, 16, 0, 0, 20, 2, 0, 43, 1, 0, 8, 0, 6, 247, 
3, 6, 89, 15, 18, 139, 48, 2, 15, 1, 2, 26, 10, 58, 181, 9, 10, 
208, 23, 3, 18, 1, 0, 42, 1, 228, 364, 55, 1, 155, 0, 172, 271, 
29, 3, 9, 4, 1, 48, 3, 2, 12, 0, 1, 70, 7, 4, 10, 2, 8, 75, 12, 
2, 8, 6, 13, 37, 3, 5, 110, 10, 4, 10, 3, 0, 28, 3, 51, 89, 23, 
3, 23, 1, 2, 104, 5, 6, 35, 4, 1, 12, 2, 23, 30, 0, 4, 26, 2, 
0, 48, 10, 5, 35, 3, 1, 95, 5, 9, 12, 101, 3, 33, 3, 0, 16, 7, 
2, 44, 6, 7, 15, 4, 0, 18, 0, 23, 188, 25, 4, 18, 1, 2, 48, 8, 
4, 69, 20, 7, 16, 2, 0, 33, 0, 1, 13, 2, 0, 10, 4, 26, 106, 32, 
3, 31, 3, 23, 190, 20, 4, 183, 31, 11, 164, 15, 13, 39, 9, 7, 
69, 10, 1, 3, 0, 14, 131, 21, 1, 15, 5, 0, 5, 0, 8, 19, 3, 12, 
59, 14, 2, 9, 0, 4, 127, 24, 3, 65, 13, 17, 19, 2, 7, 64, 4, 
29, 49, 30, 0, 6, 3, 2, 19, 7, 63, 157, 23, 41, 92, 10, 2, 60, 
17, 2, 77, 16, 31, 60, 24, 14, 26, 5, 3, 18, 1, 82, 61, 26, 2, 
9, 0, 17, 39, 6, 1, 20, 4, 24, 24, 9, 3, 6, 0, 2, 5, 0, 1, 18, 
2, 107, 133, 22, 153, 238, 19, 0, 3, 0, 12, 7, 0, 12, 40, 8, 
0, 7, 0, 19, 38, 3, 0, 6, 0, 13, 26, 8, 0, 4, 0, 0, 8, 0, 2, 
3, 0, 3, 2, 0, 15, 68, 6, 1, 2, 2, 10, 45, 1, 23, 46, 9, 27, 
45, 11, 0, 4, 0, 36, 31, 4, 5, 16, 5, 28, 63, 10, 15, 13, 6, 
16, 2, 1, 26, 24, 6, 0, 7, 0, 2, 6, 0, 2, 4, 0, 1, 18, 3, 32, 
75, 2, 0, 6, 0, 2, 4, 0, 9, 24, 12, 1, 3, 0, 0, 4, 0, 19, 54, 
2, 0, 9, 0, 0, 7, 1, 5, 43, 0, 5, 8, 0, 0, 8, 0, 6, 67, 6, 2, 
84, 0, 5, 39, 14, 10, 62, 5, 8, 19, 2, 8, 15, 9, 2, 15, 0, 10, 
51, 3, 4, 18, 6, 27, 79, 5, 18, 68, 9, 15, 46, 10, 0, 20, 8), 
    species = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
    1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
    1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
    1L, 2L, 3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L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
    1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
    1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
    1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), levels = c("Sp1", "Sp2", 
    "Sp3"), class = "factor")), row.names = 661:1743, class = "data.frame")
$\endgroup$
5
  • $\begingroup$ What exactly do you mean by "compare the mean catch between 3 species within years. "? $\endgroup$ Feb 9, 2023 at 21:26
  • $\begingroup$ @COOLSerdash I want to see if the average catch of Sp1 is different from SP2 within year 2005, 2006, ..., 2015 and same for Sp2 and SP3 and SP1 and SP3. So is the mean tournament catch different between species during each year. I have this comparison with the TukeyHSD() test. I would like to know if there is a variant available for the glm() since I can use an offset with different effort hours for each tournament. Does that clear it up? $\endgroup$
    – THATguy
    Feb 9, 2023 at 22:37
  • 1
    $\begingroup$ The software solution for the post-hoc tests is to use the emmeans package, which supports generalized linear models, and allows you to make whichever comparisons you want. ... I doubt you will need to use starting values (but I didn't try it with your data). ... Is there a family = nb option in the glm() function ? $\endgroup$ Feb 10, 2023 at 1:27
  • $\begingroup$ yes nb is negative binomial I've used it before I think the problem with the current glm is the two factor comparison haven't found a good solution yet. Thanks I'll check out emmeans $\endgroup$
    – THATguy
    Feb 10, 2023 at 3:21
  • $\begingroup$ Actually I used nb() with gam() not glm() now that I look back $\endgroup$
    – THATguy
    Feb 10, 2023 at 16:14

1 Answer 1

2
$\begingroup$

Personally, I would use either the glm.nb function from the MASS packages or the gamlss package. As @SalMangiafico said, the emmeans package can then be used for comparing the species within each year.

Here's how I would do it (I'm using your data). You see that the pairwise comparisons are on the original scale using ratios:

library(MASS)
library(emmeans)

sim_data$year <- factor(sim_data$year)

# Fit negative binomial model with offset
mod <- glm.nb(catch~year*species + offset(log(eff_hrs)), data = sim_dat)

# Inspect model
summary(mod)

# Calculate marginal means on the response scale separate for each year
em <- emmeans(mod, "species", by = "year", type = "response")

# Contrast each species within each year
contr <- contrast(em, "pairwise")
contr

year = 2005:
 contrast  ratio     SE  df null z.ratio p.value
 Sp1 / Sp2 1.488 0.4341 Inf    1   1.361  0.3614
 Sp1 / Sp3 2.507 0.7573 Inf    1   3.044  0.0066
 Sp2 / Sp3 1.685 0.5176 Inf    1   1.700  0.2052

year = 2006:
 contrast  ratio     SE  df null z.ratio p.value
 Sp1 / Sp2 0.703 0.1779 Inf    1  -1.391  0.3456
 Sp1 / Sp3 1.028 0.2618 Inf    1   0.107  0.9937
 Sp2 / Sp3 1.461 0.3697 Inf    1   1.498  0.2917

year = 2007:
 contrast  ratio     SE  df null z.ratio p.value
 Sp1 / Sp2 0.721 0.1315 Inf    1  -1.792  0.1721
 Sp1 / Sp3 1.461 0.2768 Inf    1   1.999  0.1123
 Sp2 / Sp3 2.025 0.3782 Inf    1   3.779  0.0005

The output is truncated due to its length. $P$-values are adjusted by the Tukey method for 3 estimates, so within each year. If you wanted to adjust the $p$-values for all tests, you'd have to change the adjustment method (e.g. the mvt method). Here's how you could do that (output again truncated):

test(contr, by = NULL, type = "response", adjust = "mvt")

contrast  year ratio     SE  df null z.ratio p.value
 Sp1 / Sp2 2005 1.488 0.4341 Inf    1   1.361  0.9928
 Sp1 / Sp3 2005 2.507 0.7573 Inf    1   3.044  0.0703
 Sp2 / Sp3 2005 1.685 0.5176 Inf    1   1.700  0.9198
 Sp1 / Sp2 2006 0.703 0.1779 Inf    1  -1.391  0.9905
 Sp1 / Sp3 2006 1.028 0.2618 Inf    1   0.107  1.0000
 Sp2 / Sp3 2006 1.461 0.3697 Inf    1   1.498  0.9774
 Sp1 / Sp2 2007 0.721 0.1315 Inf    1  -1.792  0.8744
 Sp1 / Sp3 2007 1.461 0.2768 Inf    1   1.999  0.7300
 Sp2 / Sp3 2007 2.025 0.3782 Inf    1   3.779  0.0051
$\endgroup$
1
  • 1
    $\begingroup$ Great! Thanks so much. $\endgroup$
    – THATguy
    Feb 10, 2023 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.