0
$\begingroup$

I'm analyzing a data set in R and I would like to have some advice on how to build my analysis to get the proper answer to my question.

I want to know if the animals stayed longer in an area, outside the area or if there's no significant difference. I also have data on the sex and size of each animal, and I want to know if these have some influence (i.e.: do males stay longer in the area than females, etc.).

Do animals stay longer in or out the area and is it influenced by Sex and Size? Simple question but I'm not sure how to build my analysis...

My data looks like this:

head(mydata)

     ID Sex Size Time.in Time.out Total.Time Prop.in Prop.out
1 33199   F   63     493      421        914  0.5394   0.4606
2 33205   M   68       0      784        784  0.0000   1.0000
3 33206   M   69       0      155        155  0.0000   1.0000
4 33207   F   62       0      230        230  0.0000   1.0000
5 33208   M   66    3969     2804       6773  0.5860   0.4140
6 33210   F   63      88      263        351  0.2515   0.7485

Note here that I have two response variables (Time.in and Time.out) for each animal. Also note that the total time that each animal was recorded (Total.Time) is different (min = 155, max = 6773 minutes). Prop.in and Prop.out is the proportion of time they spent in and out but I'm not using this for now. So it seems to me that there are different ways I can write my equation.

First one using quasibinomial (because of overdispersion):

m1 <- glm(cbind(Time.in,Time.out)~Sex*Size, data = mydata, family = quasibinomial)
summary(m1)

Call:
glm(formula = cbind(Time.in, Time.out) ~ Sex * Size, family = quasibinomial, 
data = mydata)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-33.506  -16.149  -10.275    6.586   18.655  

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -11.6407    34.1662  -0.341    0.745
SexM         10.8232    34.6930   0.312    0.766
Size          0.1788     0.5498   0.325    0.756
SexM:Size    -0.1661     0.5569  -0.298    0.776

(Dispersion parameter for quasibinomial family taken to be 401.4389)

    Null deviance: 3109.9  on 9  degrees of freedom
Residual deviance: 2913.9  on 6  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 4

So looking at the intercept, the negative slope indicates that they spent less time out of the area, however this is not significant. And then we see that Sex, Size and their interaction are not significant.

I also tried this formula but I'm not sure if that's right:

m2 <- glm(Time.in~Time.out+Sex*Size+offset(log(Total.Time)), data = mydata, family = quasipoisson)
summary(m2)

Call:
glm(formula = Time.in ~ Time.out + Sex * Size + offset(log(Total.Time)), 
family = quasipoisson, data = mydata)

Deviance Residuals: 
       1         2         3         4         5         6         7         8  
  5.6004  -23.1852   -9.5818  -12.6324   -0.0967   -4.5854    1.6991  -16.0141  
       9        10  
 -5.7422   19.2723  

Coefficients:
              Estimate Std. Error t value Pr(>|t|)
(Intercept) -8.3657927 21.8619928  -0.383    0.718
Time.out     0.0003216  0.0002717   1.183    0.290
SexM         3.2377839 22.3820096   0.145    0.891
Size         0.1166635  0.3509753   0.332    0.753
SexM:Size   -0.0607021  0.3569920  -0.170    0.872

(Dispersion parameter for quasipoisson family taken to be 221.1145)

    Null deviance: 1965.9  on 9  degrees of freedom
Residual deviance: 1505.1  on 5  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 5

Now using this formula with quasipoisson and the offset to integrate the different recording time for each animal, you can see that the estimate for Time.outis positive, so they spent more time out of the area, the opposite of the previous result! Again this is not significant but in others data set I have from other regions it becomes significant. Also, Sex and Size remain not significant.

I could also rework my data set and use mixed-models. Using this data format where I add the variable Loc (In or Out) and where each animal ID appears twice:

head(mydata2)

     ID Sex Size Loc Time Total.Time Time.prop
1 33199   F   63  In  493        914    0.5394
2 33199   F   63 Out  421        914    0.4606
3 33205   M   68  In    0        784    0.0000
4 33205   M   68 Out  784        784    1.0000
5 33206   M   69  In    0        155    0.0000
6 33206   M   69 Out  155        155    1.0000

I could possibly write this formula:

mydata2$Size <- scale(mydata2$Size)

m3 <- glmer(Time ~ Loc+Sex+Size+Loc:Sex+Loc:Size+Sex:Size+(1|ID),
                 family = poisson, data = mydata2)

summary(m3)

Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [
glmerMod]
 Family: poisson  ( log )
Formula: Time ~ Loc + Sex + Size + Loc:Sex + Loc:Size + Sex:Size + (1 |      ID)
   Data: mydata2

     AIC      BIC   logLik deviance df.resid 
  3175.1   3183.1  -1579.6   3159.1       12 

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-20.0299  -9.2971  -0.3699   9.2025  20.4754 

Random effects:
 Groups Name        Variance Std.Dev.
 ID     (Intercept) 0.8563   0.9254  
Number of obs: 20, groups:  ID, 10

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  5.36830    1.29897   4.133 3.58e-05 ***
LocOut       0.47290    0.05278   8.959  < 2e-16 ***
SexM         1.01397    1.36791   0.741    0.459    
Size         0.49477    1.60517   0.308    0.758    
LocOut:SexM -0.49963    0.05776  -8.650  < 2e-16 ***
LocOut:Size -0.12466    0.03118  -3.998 6.38e-05 ***
SexM:Size   -0.85866    1.65415  -0.519    0.604    
 ---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) LocOut SexM   Size   LcO:SM LcOt:S
LocOut      -0.025                                   
SexM        -0.950  0.025                            
Size         0.934 -0.004 -0.887                     
LocOut:SexM  0.024 -0.943 -0.026  0.005              
LocOut:Size -0.011  0.414  0.012 -0.013 -0.448       
SexM:Size   -0.906  0.001  0.825 -0.970 -0.001  0.004

Now, using ID as random variable and a poisson distribution (no overdispersion), they spent more time out and this is highly significant! And I have highly significant interaction terms.

It seems to me that the first equation (using quasibinomial) is the best but results are so different that I'm not sure. Any inputs on how to analyze this data would be greatly appreciated!

$\endgroup$
0
$\begingroup$

I am not sure to answer your question but here is some general advice.

You should check the diagnostic plots plot(lm(..)) to get some idea about heteroskewdasticity as your residuals are a bit off.

I think your problem can be simplified. Being "in" our being "out" is inverse to each other. Depending on your research question I would choose just one of these as outcome variable for starters. You can still run a second model to confirm your findings for the inverse.

Using the probability (%) of time spent for that condition seems a good choice because of the varying times that you measured an animal. You may want to consider conducting a sensitivity analysis to find out if the time you conducted the measurement influenced your result though. (if you only look short how probable is it to be crossing between the places a lot?)

You may want to plot the probabilities for time in/out (depending on your choice) vs sex and size before running a model and look at some descriptive statistics for the different groups to get an idea about the effect.

Finally, random effects or not? If you believe that there are some other factors contributing except for size and sex (mood of the animal -> ID; weather/season?), that's the model to go with. It depends on your research question. I would advise to run the model without random effects first and to compare the two.

Hope this helps!

$\endgroup$
  • $\begingroup$ I checked the diagnostic plots on the full dataset and they seem ok to me. I also did some data exploration but since there is a lot of variation in my data (e.g.: some individuals spend 0 Time.in but others can spend days and the same is true for the Time.out) it's difficult to get a clear picture of what's going on visually (yes they seem to spend more time out, but is it significant? Probably not). Now, I expect that since I have a lot of variation, I might not see a significant difference, still I want to find the best way to analyze this data to report my results accurately. $\endgroup$ – Mud Warrior Apr 27 '17 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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