Rate of drop analysis: Difference between revisions
No edit summary |
No edit summary |
||
| Line 12: | Line 12: | ||
==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 | |||