Skip to content

Instantly share code, notes, and snippets.

View MJacobs1985's full-sized avatar

Marc Jacobs MJacobs1985

View GitHub Profile
## Interference
Interference_BPI2<-Interference_BPI
Interference_BPI2<-ddply(Interference_BPI2,.(Patientnr),.drop=FALSE,transform,baselinechange=Interference-Interference[1])
Interference_BPI3<-Interference_BPI
Interference_BPI3<-ddply(Interference_BPI3,.(Patientnr),.drop=FALSE,transform,change=Interference-lag(Interference))
Interference_BPI$Interference_baselinechange<-Interference_BPI2$baselinechange
Interference_BPI$Interference_change<-Interference_BPI3$change
Interference_BPI$Interference_baselinechange[Interference_BPI$time==0]<-NA
Interference_BPI$Interference_change[Interference_BPI$time==0]<-NA
Interference_BPI
Severity_BPI2<-Severity_BPI
Severity_BPI2<-ddply(Severity_BPI2,.(Patientnr),.drop=FALSE,transform,baselinechange=Severity-Severity[1])
Severity_BPI3<-Severity_BPI
Severity_BPI3<-ddply(Severity_BPI3,.(Patientnr),.drop=FALSE,transform,change=Severity-lag(Severity))
Severity_BPI$Severity_baselinechange<-Severity_BPI2$baselinechange
Severity_BPI$Severity_change<-Severity_BPI3$change
Severity_BPI$Severity_baselinechange[Severity_BPI$time==0]<-NA
Severity_BPI$Severity_change[Severity_BPI$time==0]<-NA
Severity_BPI
# Check visually if worked
str(bpi_combined)
bpi_combined2<-bpi_combined
bpi_combined2<-ddply(bpi_combined2,.(Patientnr),.drop=FALSE,transform,baselinechange=value-value[1])
bpi_combined3<-bpi_combined
bpi_combined3<-ddply(bpi_combined3,.(Patientnr),.drop=FALSE,transform,change=value-lag(value))
bpi_combined$bpi_baselinechange<-bpi_combined2$baselinechange
bpi_combined$bpi_change<-bpi_combined3$change
bpi_combined$bpi_baselinechange[bpi_combined$time==0]<-NA
bpi_combined$bpi_change[bpi_combined$time==0]<-NA
str(bpi_combined)
try<-bpi_combined%>%dplyr::select(Patientnr,time,variable,value)%>%
dplyr::filter(variable=="BPI_7A"|variable=="BPI_7B"|variable=="BPI_7C"|
variable=="BPI_7D"|variable=="BPI_7E"|variable=="BPI_7F"|
variable=="BPI_7G")%>%
dplyr::group_by(Patientnr,time)%>%arrange(Patientnr, time);try
g1<-ggplot(try, aes(x=as.factor(time),y=as.factor(variable),fill=as.factor(value)))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = TRUE, option="magma", direction = -1 )+
facet_wrap(~Patientnr)+
theme_grey(base_size=10)+marc_discrete
try<-bpi_combined%>%dplyr::select(Patientnr,time,variable,value)%>%
dplyr::filter(variable=="BPI_2_"|variable=="BPI_3_"|variable=="BPI_4_")%>%
dplyr::group_by(Patientnr,time)%>%arrange(Patientnr, time);try
g1<-ggplot(try, aes(x=as.factor(time),y=as.factor(variable),fill=as.factor(value)))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = TRUE, option="magma", direction = -1 )+
facet_wrap(~Patientnr)+
theme_grey(base_size=10)+marc_discrete
Severity_BPI<-try%>%dplyr::summarise(Severity=mean(value));head(Severity_BPI);histogram(Severity_BPI$Severity)
g4<-ggplot(Severity_BPI, aes(x=as.factor(time), y=Severity))+geom_boxplot()+theme_classic2()+labs(x="time")
NV_QOL<-try%>%
dplyr::summarise(variable = c("QOL_9_"),
q9 = mean(value)) %>%
dplyr::mutate(nv = case_when(
q9 == 1 ~ 0,
q9 == 2 ~ 100/6,
q9 == 3 ~ 50,
q9 == 4 ~ 100,
TRUE ~ -1));head(NV_QOL)
NV_QOL$nv<-ifelse(NV_QOL$nv==-1, NA, NV_QOL$nv)
try<-qol_combined%>%dplyr::select(Patientnr,time,variable,value)%>%
dplyr::filter(variable=="QOL_7_"|variable=="QOL_11")%>%
dplyr::group_by(Patientnr,time)%>%arrange(Patientnr, time);head(try);dim(try)
g1<-ggplot(try, aes(x=as.factor(time),y=as.factor(variable),fill=as.factor(value)))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = TRUE, option="magma", direction = -1 )+
facet_wrap(~Patientnr)+
theme_grey(base_size=10)+marc_discrete
FA_QOL<-try%>%
dplyr::summarise(variable=variable, value=value, fa = sum(value), fasum = fa-2) %>%
try<-qol_combined%>%dplyr::select(Patientnr,time,variable,value)%>%
dplyr::filter(variable=="QOL_13"|variable=="QOL_14")%>%
dplyr::group_by(Patientnr,time)%>%arrange(Patientnr, time);head(try);dim(try)
g1<-ggplot(try, aes(x=as.factor(time),y=as.factor(variable),fill=as.factor(value)))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = TRUE, option="magma", direction = -1 )+
facet_wrap(~Patientnr)+
theme_grey(base_size=10)+marc_discrete
EF_QOL<-try%>%dplyr::summarise(ef = sum(value), efsum = 8-ef) %>%
try<-qol_combined%>%dplyr::select(Patientnr,variable,time,value)%>%
dplyr::filter(variable=="QOL_1_"|variable=="QOL_2_"|variable=="QOL_3_")%>%
dplyr::group_by(Patientnr,time)%>%arrange(Patientnr, time);head(try)
g1<-ggplot(try, aes(x=as.factor(time),y=as.factor(variable),fill=as.factor(value)))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = TRUE, option="magma", direction = -1 )+
facet_wrap(~Patientnr)+
theme_grey(base_size=10)+marc_discrete # shows that, although missing across patients and across time, there are no missing within a form. Hence, I expect to have pf2 values!
PF_QOL<-try%>%
dplyr::summarise(pf = sum(value), pfsum = 12-pf) %>%
qol_combined<-rbind(pan_qol_YN_melt,
pan_qol_1_melt,
pan_qol_2_melt,
pan_qol_3_melt,
pan_qol_4_melt,
pan_qol_5_melt,
pan_qol_6_melt,
pan_qol_7_melt,
pan_qol_8_melt,
pan_qol_9_melt,