1
$\begingroup$

I'm looking at whether the intake rate of a monkey eating leaves changes from the first quarter of time spent in a tree to the last quarter.

I've analysed this generally, but now I want to stratify by food type, to see if the food type leads to a significant change.

Here is a sample of my data:

Intake.Q1 Intake.Q4 FOOD.TYPE
6 6 M
19.5 5 M
5.1 2.5 M
4.8 2.1 Y
10.6 5.4 Y
6 2.5 Y

This is the code I used to generally do a t-test on all data, regardless of food type. t.test(R_DATA$Intake.Q1,R_DATA$Intake.Q4)

What would I add to this code in order to stratify based on 'M' and 'Y', so I can see whether there was a significant change in intake rate between Q1 and Q4 when eating Mature leaves, and the same for Young leaves?

$\endgroup$

1 Answer 1

1
$\begingroup$

The t.test is for comparing only 2 conditions A vs B. Your problem is A vs B vs C.

So one option is to perform 2 separate t.test and compare Q1 to Q4 for both Food types.

The other option is to perform a ANOVA on the data. An for this it is easier to rearrange the data.

R_DATA <- structure(list(Intake.Q1 = c(6, 19.5, 5.1, 4.8, 10.6, 6), 
                         Intake.Q2 = c(6, 5, 2.5, 2.1, 5.4, 2.5), 
                         Food.Type = c("M", "M", "M", "Y", "Y", "Y")), 
                    class = "data.frame", row.names = c(NA, -6L))

library(tidyr)
df_long <-pivot_longer(R_DATA, cols= -Food.Type,  names_to= "Intake")

results <-aov(value ~ Intake * Food.Type, data=df_long)

summary(results)

             Df Sum Sq Mean Sq F value Pr(>F)
Intake            1  67.69   67.69   3.345  0.105
Food.Type         1  13.44   13.44   0.664  0.439
Intake:Food.Type  1   2.71    2.71   0.134  0.724
Residuals         8 161.87   20.23               
$\endgroup$

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.