Skip to content

Instantly share code, notes, and snippets.

View MJacobs1985's full-sized avatar

Marc Jacobs MJacobs1985

View GitHub Profile
DataExplorer::plot_qq(total[,c(12,15,19,20,23,26,29,32,35,38,42,79)], by="timef", ggtheme=theme_bw())
ggplot(total) + geom_bar(aes(x=timef, y=Severity, fill=Tumorsite_in_pancreas), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Gender) + theme_bw()
ggplot(total) + geom_bar(aes(x=timef, y=Severity, fill=timef), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Tumorsite_in_pancreas) + theme_bw()
ggplot(total) + geom_bar(aes(x=timef, y=Severity, fill=timef), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Opioid_spec) + theme_bw()
ggplot(total) + geom_bar(aes(x=timef, y=Severity, fill=timef), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Non_opioid_spec) + theme_bw()
ggplot(total) + geom_bar(aes(x=timef, y=Severity, fill=timef), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Gender) + theme_bw()
ggplot(total) + geom_bar(aes(x=timef, y=Severity, fill=timef), position = "dodge", stat = "summary", fun.y = "mean")
DataExplorer::plot_density(total, ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,42)], by="Gender", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,55)], by="Opioid_spec", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,52)], by="Non_opioid_spec", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,43)], by="Performance_status_at_consultation", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,47)], by="Surgery_prior_to_consultation", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,48)], by="Chemotherapy_prior_to_consultation", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(12,15,19,20,23,26,29,32,35,38,79)], by="timef", ggtheme=theme_bw())
DataExplorer::plot_boxplot(total[,c(15,26,32,35,79)], by="timef", ggtheme=theme_bw())
pairs.panels(total[,c(3,6,9,41,44,81,80)], method = "pearson", hist.col = "#00AFBB",density = TRUE,ellipses = TRUE)
ggplot() +
geom_line(data=total, mapping=aes(x=time, y=Severity)) +
geom_point(data=total, mapping=aes(x=time, y=Severity)) +
facet_wrap(~Patientnr, scales="free_x") + coord_cartesian(ylim = c(0, 10)) +
geom_vline(pancreas, mapping=aes(xintercept = SurvTimeWeek), linetype="dotted", color = "red", size=1.0) +
theme_bw()
ggplot() +
geom_line(data=total, mapping=aes(x=time, y= Overall_QOL)) +
geom_point(data=total, mapping=aes(x=time, y=Overall_QOL)) +
fit<-total%>%filter(!Patientnr%in%8 & !Patientnr%in%20 & !Patientnr%in%16)%>%lm(SurvTimeWeek~Severity*ns(time,3), data=.);summary(fit);par(mfrow = c(2, 2));plot(fit);plot(allEffects(fit))
fit<-total%>%filter(!Patientnr%in%8 & !Patientnr%in%20 & !Patientnr%in%16)%>%lm(SurvTimeWeek~Interference*ns(time,3), data=.);summary(fit);par(mfrow = c(2, 2));plot(fit);plot(allEffects(fit))
fit<-total%>%filter(!Patientnr%in%8 & !Patientnr%in%20 & !Patientnr%in%16)%>%lm(SurvTimeWeek~Relief*ns(time,3), data=.);summary(fit);par(mfrow = c(2, 2));plot(fit);plot(allEffects(fit))
fit<-total%>%filter(!Patientnr%in%8 & !Patientnr%in%20 & !Patientnr%in%16)%>%lm(SurvTimeWeek~Physical_Functioning*ns(time,3), data=.);summary(fit);par(mfrow = c(2, 2));plot(fit);plot(allEffects(fit))
fit<-total%>%filter(!Patientnr%in%8 & !Patientnr%in%20 & !Patientnr%in%16)%>%lm(SurvTimeWeek~Emotional_Functioning*ns(time,3), data=.);summary(fit);par(mfrow = c(2, 2));plot(fit);plot(allEffects(fit))
fit<-total%>%filter(!Patientnr%in%8 & !Patientnr%in%20 &
g1<-ggplot(total[!total$Patientnr==8, ],
aes(x=SurvTimeWeek))+ geom_density(color="darkblue", fill="lightblue")+theme_bw()
g2<-ggplot(total[!total$Patientnr==8, ],
aes(x=SurvTimeWeek, fill=Performance_status_at_consultation))+
geom_density(alpha=0.5)+theme_bw()
g3<-ggplot(total[!total$Patientnr==8, ],aes(x=SurvTimeWeek, fill=Gender))+
geom_density(alpha=0.5)+theme_bw()
g4<-ggplot(total[!total$Patientnr==8, ],aes(x=SurvTimeWeek, fill=Disease_stage_at_consultation))+
geom_density(alpha=0.5)+theme_bw()
g5<-ggplot(total[!total$Patientnr==8, ],
total$timef <-as.factor(total$time)
total$BMI<-total$Weight_at_consultation/((total$Length_at_consultation/100)^2)
## Order data and remove duplicates
head(total%>%group_by(Patientnr,time)%>%arrange(Patientnr,time));dim(total)
total<-total[!duplicated(total),];dim(total)
## The time and Survtime need to be on the same scale for joint modelling - transform to weeks
total$SurvTimeWeek<-total$SurvTime/7
pancreas$SurvTimeWeek<-pancreas$SurvTime/7
## Clean all the datasets, a lot of duplicates
Severity_BPI<-Severity_BPI[!duplicated(Severity_BPI[c(1:5)]),];head(Severity_BPI)
Interference_BPI<-Interference_BPI[!duplicated(Interference_BPI[c(1:5)]),];head(Interference_BPI)
PF_QOL<-PF_QOL[!duplicated(PF_QOL[c(1,2,5:7)]),];head(PF_QOL)
EF_QOL<-EF_QOL[!duplicated(EF_QOL[c(1,2,3:5)]),];head(EF_QOL)
FA_QOL<-FA_QOL[!duplicated(FA_QOL[c(1,2,3:5)]),];head(FA_QOL)
NV_QOL<-NV_QOL[!duplicated(NV_QOL[c(1,2,3:5)]),];head(NV_QOL)
PA_QOL<-PA_QOL[!duplicated(PA_QOL[c(1,2,5:5)]),];head(PA_QOL)
DY_QOL<-DY_QOL[!duplicated(DY_QOL[c(1,2,5:5)]),];head(DY_QOL)
SL_QOL<-SL_QOL[!duplicated(SL_QOL[c(1,2,5:5)]),];head(SL_QOL)
## QOL transformed scales
## PF_QOL
PF_QOL2<-PF_QOL
PF_QOL2<-ddply(PF_QOL2,.(Patientnr),.drop=FALSE,transform,baselinechange=pf2-pf2[1])
PF_QOL3<-PF_QOL
PF_QOL3<-ddply(PF_QOL3,.(Patientnr),.drop=FALSE,transform,change=pf2-lag(pf2))
PF_QOL$pf2_baselinechange<-PF_QOL2$baselinechange
PF_QOL$pf2_change<-PF_QOL3$change
PF_QOL$pf2_baselinechange[PF_QOL$time==0]<-NA
PF_QOL$pf2_change[PF_QOL$time==0]<-NA
## 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