Difference between revisions of "Rate of drop analysis"
m (→Sample R Code) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
1. First, filter your ITT data to contain only the observations from where animals are in the initial drop of the experiment. This is usually 30-45 minutes, but you should assess this for each ITT yourself. | 1. First, filter your ITT data to contain only the observations from where animals are in the initial drop of the experiment. This is usually 30-45 minutes, but you should assess this for each ITT yourself. | ||
− | 2. You then need to construct a | + | 2. You then need to construct a model for your data. It should include 1 covariate for every experimental variable (eg, time, genotype, sex, diet, injection). You should also include an interaction variable for time and the variable of interest. This will be the crucial value that you interpret different slopes of the initial drop from. |
3. After creating the model, you will need to assess the significance of that model. Do this using the anova command in R. This will give you the covariate p values. | 3. After creating the model, you will need to assess the significance of that model. Do this using the anova command in R. This will give you the covariate p values. | ||
− | 4. Next, to find the beta estimates, you will need to run the coefficient command in R. This will tell you the actual changes in glucose (mg/dL) for each covariate. The beta coefficient of interest is the one corresponding to the interaction variable you coded in step 2. | + | 4. Next, to find the beta estimates, you will need to run the coefficient command in R. This will tell you the actual changes in glucose (mg/dL) for each covariate. The beta coefficient of interest is the one corresponding to the interaction variable you coded in step 2. |
− | + | ||
==Sample R Code== | ==Sample R Code== | ||
− | + | models<-ITT.raw.data%>% | |
− | filter(time== | + | filter(time<60)%>% |
+ | group_by(ID, sex, treatment)%>% | ||
+ | mutate(l.glucose = log(glucose))%>% | ||
+ | do(fitted.model= lm(l.glucose~ time, data =.))%>% | ||
+ | mutate(rate =coef(fitted.model)["time"], | ||
+ | max = coef(fitted.model)["(Intercept)"], | ||
+ | rsq = summary(fitted.model)$r.squared)%>% | ||
+ | mutate(max.exp = exp(max))%>% | ||
+ | mutate( slope= max.exp*rate) | ||
+ | |||
− | + | summary.models<-models%>% | |
+ | group_by(sex,treatment)%>% | ||
+ | summarise_at(.var ="slope", .funs = funs(mean, se)) | ||
− | + | ggplot(summary.models, aes(treatment, mean, fill = treatment))+ | |
+ | geom_col(aes(fill = treatment))+ | ||
+ | facet_grid(.~sex)+ | ||
+ | geom_errorbar(aes(ymin = mean-se, ymax = mean + se), width = 0.3)+ | ||
+ | scale_fill_manual(values = color.scheme)+ | ||
+ | labs(title = "Rate of Drop, ITT",y="mg/dL per minute") | ||
− | + | rate.aov<-aov(slope ~ sex + treatment, data = models) | |
+ | anova(rate.aov)%>%kable |
Latest revision as of 13:54, 1 September 2022
Purpose
To assess the initial response to insulin administration, you can calculate the slope of the line for the early timepoints in your insulin tolerance test. To do this, complete the following steps:
Methods
1. First, filter your ITT data to contain only the observations from where animals are in the initial drop of the experiment. This is usually 30-45 minutes, but you should assess this for each ITT yourself.
2. You then need to construct a model for your data. It should include 1 covariate for every experimental variable (eg, time, genotype, sex, diet, injection). You should also include an interaction variable for time and the variable of interest. This will be the crucial value that you interpret different slopes of the initial drop from.
3. After creating the model, you will need to assess the significance of that model. Do this using the anova command in R. This will give you the covariate p values.
4. Next, to find the beta estimates, you will need to run the coefficient command in R. This will tell you the actual changes in glucose (mg/dL) for each covariate. The beta coefficient of interest is the one corresponding to the interaction variable you coded in step 2.
Sample R Code
models<-ITT.raw.data%>%
filter(time<60)%>% group_by(ID, sex, treatment)%>% mutate(l.glucose = log(glucose))%>% do(fitted.model= lm(l.glucose~ time, data =.))%>% mutate(rate =coef(fitted.model)["time"], max = coef(fitted.model)["(Intercept)"], rsq = summary(fitted.model)$r.squared)%>% mutate(max.exp = exp(max))%>% mutate( slope= max.exp*rate)
summary.models<-models%>%
group_by(sex,treatment)%>%
summarise_at(.var ="slope", .funs = funs(mean, se))
ggplot(summary.models, aes(treatment, mean, fill = treatment))+
geom_col(aes(fill = treatment))+ facet_grid(.~sex)+ geom_errorbar(aes(ymin = mean-se, ymax = mean + se), width = 0.3)+ scale_fill_manual(values = color.scheme)+ labs(title = "Rate of Drop, ITT",y="mg/dL per minute")
rate.aov<-aov(slope ~ sex + treatment, data = models) anova(rate.aov)%>%kable