Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created November 9, 2022 16:13
Show Gist options
  • Save MJacobs1985/f3a264558112513c496b5e07541aa01c to your computer and use it in GitHub Desktop.
Save MJacobs1985/f3a264558112513c496b5e07541aa01c to your computer and use it in GitHub Desktop.
## QOL original scales
str(qol_combined)
qol_combined2<-qol_combined
qol_combined2<-ddply(qol_combined2,.(Patientnr),.drop=FALSE,transform,baselinechange=value-value[1])
qol_combined3<-qol_combined
qol_combined3<-ddply(qol_combined3,.(Patientnr),.drop=FALSE,transform,change=value-lag(value))
qol_combined$qol_baselinechange<-qol_combined2$baselinechange
qol_combined$qol_change<-qol_combined3$change
qol_combined$qol_baselinechange[qol_combined$time==0]<-NA
qol_combined$qol_change[qol_combined$time==0]<-NA
str(qol_combined)
# Check visually if worked
g1<-ggplot(qol_combined) + geom_bar(aes(as.factor(time), qol_baselinechange), position = "dodge", stat = "summary", fun.y = "mean") +facet_wrap(~variable,scales = "free") + theme_bw()
g2<-ggplot(qol_combined) + geom_bar(aes(as.factor(time), qol_change), position = "dodge", stat = "summary", fun.y = "mean") +facet_wrap(~variable, scales = "free") + theme_bw()
grid.arrange(g1,g2,ncol=2, top="QOL Changes ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment