#for enquiries: contact harshaldeshmukh@nhs.net #R code for FSL analysis # calcualtes the average pre-FSL and average post-FSL HbA1c and does a t.test, Mann-Whitney-Wilcoxon test and also does draws a boxplot of pre and post-FSL # Calcualtes average Pre-FSL and average post-FSL gold score and and does t-test and draws box plot # gives average of pre and post fsl hypo and hyperglycaemic-DKA related admissions and paramidic call outs #Download and install R from here (https://www.r-project.org/) #Save your FSL audit download in your working folder/directory and name it file.csv. #Save the file code FSLcode.txt the folder where you have saved your data #Set working directory in R conosole. This is the folder where your FSL data download and Rcode file FSLcode.txt is saved. Using command below. remove the "#". #----type>>> setwd("C:/Users/arunb/Desktop/fsldata") (--use forward slashes not backward slashes) #Open R and Paste the command in the R console >>>> source("FSLcode_Hba1c_analysis.txt") #reads data from the computer. data1<-read.csv("file.csv", header=TRUE) #gets average of postFSL HbA1c data1$average_preFSL<- rowMeans(data1[c('X.1.HbA1c..Xmmol.mol.', 'X2HbA1c..Xmmol.mol.','X3HbA1c..Xmmol.mol.','X4HbA1c..Xmmol.mol.','X5HbA1c..Xmmol.mol.')], na.rm=TRUE) #gets average of postFSL HbA1c data1$average_postFSL<- rowMeans(data1[c('follow.up...5.HbA1c.since.last.visit...OR..Xmmol.mol.', 'follow.up...4..HbA1c.since.last.visit...OR..Xmmol.mol.','follow.up...3..HbA1c.since.last.visit...OR..Xmmol.mol.','follow.up...2..HbA1c.since.last.visit.....OR..Xmmol.mol.','follow.up...1.HbA1c.since.last.visit..OR..Xmmol.mol.')], na.rm=TRUE) #this command removes patients with no follow-up myvars<-c("Identifier", "average_preFSL","DDSC1..Feeling.overwhelmed.by.the.demands.of.living.with.diabetes", "DDSC2..Feeling.that.I.am.often.failing.with.my.diabetes.routine", "Number.of.admissions...Hyperglycaemia.DKA", "Number.of.admissions...Hypoglycaemia", "Paramedic.call.outs...Hyperglycaemia.DKA", "Paramedic.call.outs...Hypoglycaemia", "Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.") datapre1<-data1[myvars] datapre1<-datapre1[complete.cases(datapre1$average_preFSL), ] datapre1<-datapre1[!duplicated(datapre1$Identifier), ] ##### myvars1<-c("Identifier", "average_postFSL","DDSC1..Feeling.overwhelmed.by.the.demands.of.living.with.diabetes", "DDSC2..Feeling.that.I.am.often.failing.with.my.diabetes.routine", "follow.up...Number.of.admissions...Hyperglycaemia.DKA" ,"follow.up..Number.of.admissions...Hypoglycaemia","follow.up..Paramedic.call.outs...Hyperglycaemia.DKA" , "follow.up..Paramedic.call.outs...Hypoglycaemia" , "follow.up...Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.") datapost1<-data1[myvars1] datapost1<-datapost1[complete.cases(datapost1$average_postFSL), ] datapost1<-datapost1[!duplicated(datapost1$Identifier), ] all<-merge(datapost1,datapre1, by="Identifier", sort=TRUE, all.x=TRUE, all.y=TRUE) all_no_dup<-all[!duplicated(all$Identifier), ] #Does t-test and writes the output of t.test. t.test(all_no_dup$average_postFSL,all_no_dup$average_preFSL) capture.output(t.test(all_no_dup$average_postFSL,all_no_dup$average_preFSL),file="t.test.txt") # Does the non-parmetric equivalent or T-test i.e. Mann-Whitney-Wilcoxon Test. prefer that you use this one wilcox.test(all_no_dup$average_postFSL,all_no_dup$average_preFSL) capture.output(wilcox.test(all_no_dup$average_postFSL,all_no_dup$average_preFSL),file="wilcox.test.txt") jpeg('HbA1c_rplot.jpg') boxplot(all_no_dup$average_preFSL,all_no_dup$average_postFSL, main = "Median HbA1c Pre and Post FSL", at = c(1,2), names = c("PreFSL", "PostFSL"), las = 2, col = c("black","black"), border = "brown", horizontal = FALSE, notch = TRUE, outline=FALSE) dev.off() t.test(all_no_dup$Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.,all_no_dup$follow.up...Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.) capture.output(t.test(all_no_dup$Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.,all_no_dup$follow.up...Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.),file="t.test_gold_score.txt") jpeg('Gold_score_rplot.jpg') boxplot(all_no_dup$Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing.,all_no_dup$follow.up...Assessment.of.awareness.of.hypoglycaemia..Gold.Score...Does.the.patient.know.when.hypos.are.commencing., main = "Median GOLD score Pre and Post FSL", at = c(1,2), names = c("PreFSL", "PostFSL"), las = 2, col = c("black","black"), border = "brown", horizontal = FALSE, notch = TRUE, outline=FALSE) dev.off() #Hospital admissions due to hypo all_no_dup1<-all_no_dup[complete.cases(all_no_dup$average_postFSL), ] sum(all_no_dup1$Number.of.admissions...Hypoglycaemia,na.rm=TRUE) sum(all_no_dup1$follow.up..Number.of.admissions...Hypoglycaemia,na.rm=TRUE) capture.output(sum(all_no_dup1$Number.of.admissions...Hypoglycaemia,na.rm=TRUE),file="hypo_admission_preFSL.txt") capture.output(sum(all_no_dup1$follow.up..Number.of.admissions...Hypoglycaemia,na.rm=TRUE),file="hypo_admission_postFSL.txt") #Hypo_para_medic_call_outs sum(all_no_dup1$Paramedic.call.outs...Hypoglycaemia,na.rm=TRUE) sum(all_no_dup1$follow.up..Paramedic.call.outs...Hypoglycaemia,na.rm=TRUE) capture.output(sum(all_no_dup1$Paramedic.call.outs...Hypoglycaemia,na.rm=TRUE),file="Paramedic_hypo_calls_preFSL.txt") capture.output(sum(all_no_dup1$follow.up..Paramedic.call.outs...Hypoglycaemia,na.rm=TRUE),file="Paramedic_hypo_calls_postFSL.txt") # Hospital admissions due to DKA-Hyperglycaemia all_no_dup2 <- all_no_dup1[ which(all_no_dup1$Number.of.admissions...Hyperglycaemia.DKA < 20), ] sum(all_no_dup2$Number.of.admissions...Hyperglycaemia.DKA,na.rm=TRUE) sum(all_no_dup2$follow.up...Number.of.admissions...Hyperglycaemia.DKA,na.rm=TRUE) capture.output(sum(all_no_dup2$Number.of.admissions...Hyperglycaemia.DKA,na.rm=TRUE),file="DKA_admission_preFSL.txt") capture.output(sum(all_no_dup2$follow.up...Number.of.admissions...Hyperglycaemia.DKA,na.rm=TRUE),file="DKA_admission_postFSL.txt")