Experiment Design
Mice belonging to knock-out ($n=7$) and wild-type ($n=6$) had their food intake recorded per hour across a 24 hour period. Within this 24 hour period, the first 12 hours is labelled as "light phase" while the remainder 12 hours is labelled as the "dark phase". Food-intake is considered a continuous data type.
My research question is to see within each dark and light phases whether there is a significant difference between knock-out and wild-type mice?
R code
I want to see if there is a difference between groups (i.e. knock-out vs wild-type) on the average food intake per hour (i.e. g/hour) within phases (i.e. light phase vs dark phase). I am graphing this as a cluster bar graph where phase type is on the x-axis and groups are the bar graphs.
model<-glm(food_intake~group*phase,data=df,family=Gamma(link=log))
s_test<-shapiro.test(residuals(model)) #Normality of residuals
if(s_test$p.value>=0.05){#if normal distribution
stats<-Anova(model,type="II")
em<-emmeans(model,~groupphase)
p<-pairs(em,adjust="bonferroni")
} else {#not normal distributed
stats<-summary.glm(model)$coefficients
em<-emmeans(model,~groupphase)
p<-pairs(em,adjust="bonferroni")
}
I want to ask whether this code is correct when conducting a post-hoc analysis using Bonferroni tests after testing for normality? From the pairwise comparison, I then use the p-values to show significance, if any, on a cluster bar graph (code not shown).
summaryandemmeansmake? You are doing the same in both cases (possibly using different contrasts). Normality tests are pretty much never a good idea either. If there are issues with model fit you should change the model, not the way you try to draw inference from it. – PBulls Nov 10 '23 at 06:04