########################################### #### Supplementary materials for ########## #### Long-term experience sampling ######## ###### in the treatment of ############### ######### bipolar disorder ################ ############## Bos et al. ################# ########################################### #libaries library(truncnorm) library(tidyverse) library(autovarCore) ########################################## ########## create data set ############### ########################################## #set seed so the numbers remain the same set.seed(16) #simulate five esm variables that change over time #average no of assessments was 491, we stick close to that number here simvar1<-c(rtruncnorm(250,a=0, b=100, mean=20,sd=22),rtruncnorm(250,a=0, b=100, mean=60,sd=22)) simvar2<-c(rtruncnorm(350,a=0, b=100, mean=58,sd=10),rtruncnorm(150,a=0, b=100, mean=40,sd=10)) #now some variables that might signal a manic episode simvar3<-c(rtruncnorm(370,a=0, b=100, mean=8,sd=13),rtruncnorm(50,a=0, b=100, mean=55,sd=15), rtruncnorm(80,a=0, b=100, mean=8,sd=13)) simvar4<-c(rtruncnorm(360,a=0, b=100, mean=15,sd=11),rtruncnorm(60,a=0, b=100, mean=50,sd=15), rtruncnorm(80,a=0, b=100, mean=15,sd=11)) simvar5<-c(rtruncnorm(360,a=0, b=100, mean=15,sd=11),rtruncnorm(60,a=0, b=100, mean=30,sd=12), rtruncnorm(80,a=0, b=100, mean=15,sd=11)) #create variables to indicate time, beep number and day number time<-c(1:500) beepno<-rep(1:5,times=100) dayno<-rep(1:100,each=5) #create date variable, we need it for some of the plots #note that this does not really correspond to our 5x3h schedule, but that doesn't matter for our purposes date<-seq( from=as.POSIXct("2022-05-01 0","%Y-%m-%d %H",tz="UTC"), length.out = 500, by="hour") #knit everything together in datafile simdata<-as.data.frame(cbind(time,beepno,dayno,simvar1,simvar2,simvar3,simvar4,simvar5,date)) #let's simulate some missingness, close to the 76% average compliance rate in our sample c_names = c("simvar1","simvar2","simvar3","simvar4","simvar5") prc_missing = 0.24 n_remove = prc_missing*nrow(simdata) simdata_mis<-simdata %>% gather(var,value,-time) %>% #reshape data sample_frac(1)%>% group_by(var)%>% mutate(value=ifelse(var%in% c_names&row_number()<=n_remove,NA,value))%>% spread(var,value) #reshape to original format #name variables variables<-c("time", "beepno", "dayno","cheerful","down","agitation","distracted","thoughts racing") lables.main<-c("time", "beepno", "dayno","I feel cheerful","I feel down","I feel agitated","I am easily distracted","My thoughts are racing") lables.under<-c("time","beepno","dayno","Not at all","Not at all", "Not at all","Not at all","Not at all") lables.above<-c("time","beepno","dayno","Very much","Very much", "Very much","Very much","Very much") ########################################## ######### GRAPH 1: Missingness ########### ########################################## #create subsets for the different time points times<-c("10.00","13.00","16.00","19.00","22.00") p1<-subset(simdata_mis,beepno==1) p2<-subset(simdata_mis,beepno==2) p3<-subset(simdata_mis,beepno==3) p4<-subset(simdata_mis,beepno==4) p5<-subset(simdata_mis,beepno==5) #calculate percentage completed entries per beep p1miss<-100-(sum(is.na(p1$simvar1))/nrow(p1))*100 p2miss<-100-(sum(is.na(p2$simvar1))/nrow(p2))*100 p3miss<-100-(sum(is.na(p3$simvar1))/nrow(p3))*100 p4miss<-100-(sum(is.na(p4$simvar1))/nrow(p4))*100 p5miss<-100-(sum(is.na(p5$simvar1))/nrow(p5))*100 plot.miss<-c(p1miss,p2miss,p3miss,p4miss,p5miss) barplot(plot.miss,main="Percentage completed assessments",names=times,cex.main=2,ylim=c(0,100), col = "chocolate1") ########################################## ######### GRAPH 2: Time of day ########### ########################################## #for diurnal variation, we make bar plots with error margins so we can see whether differences #are significant alpha<-0.05 #for 95% CIs treatment=as.factor(times) n=tapply(simdata_mis$simvar1,simdata$beepno,length) #calculate number of observations mean.simvar1<-as.numeric(tapply(simdata$simvar1,simdata$beepno,mean,na.rm=T)) #calculate mean sd.simvar1<-as.numeric(tapply(simdata$simvar1,simdata$beepno,sd,na.rm=T)) #calculate sd sem.simvar1<-as.numeric(sd.simvar1/sqrt(n)) #calculate standard error of mean margerr.simvar1<-as.numeric(qt(1-alpha/2,d=n)*sem.simvar1) #calculate margin of error data.simvar1<-as.data.frame(cbind(treatment,mean.simvar1,sd.simvar1,sem.simvar1,margerr.simvar1)) #for demonstration purposes, we make another graph with large diurnal variation mean.simdem<-c(33.1,44.3,55.8,49.2,22.1) sd.simdem<-c(14.9,12.3,11.0,11.9,13.3) margerr.simdem<-as.numeric(qt(1-alpha/2,d=n)*sem.simvar1) #Now plot the info in GGplot ggplot(data.simvar1, aes(x = treatment, y = mean.simdem)) + geom_bar(position = position_dodge(), stat="identity", fill="chartreuse3") + geom_errorbar(aes(ymin=mean.simdem-margerr.simdem, ymax=mean.simdem+margerr.simdem)) + scale_y_continuous(name="I feel down",limits=c(0,100),breaks=c(0,20,40,60,80,100))+ scale_x_discrete(name="",limits=times)+ theme(text=element_text(size=20)) #enlarge axis text ###################################################### ######### GRAPH 3: Frequency of activities ########### ###################################################### #make data frame act<-c(rtruncnorm(13,a=0, b=100, mean=50,sd=10)) act_names=c("Sleeping", "Household chores/groceries", "Working/studying", "Doing sports", "Something relaxed", "Hobby", "A trip", "Something together with others","Self-care", "Resting/nothing", "Something intimate", "On the way", "Something else") act_dt1<-as.data.frame(cbind(act_names,as.numeric(act))) act_dt1$V2<-as.numeric(as.character(act_dt1$V2)) act_dt<-act_dt1[order(-act_dt1$V2),] act_col<-c("chartreuse", "brown1","blue","yellow","darkgreen","deepskyblue","darkorange", "darkred","darkslategray1","gray44","olivedrab1", "deeppink","turquoise1") #make the plot ggplot(act_dt,aes(x=reorder(act_names,V2),y=V2))+ geom_bar(stat="identity",fill=rev(rainbow(13)))+ scale_y_continuous(name="Percentage",limits=c(0,100),breaks=c(0,20,40,60,80,100))+ scale_x_discrete(name="")+ labs(x="act_names")+ coord_flip()+ theme(text=element_text(size=20)) #enlarge axis text ###################################################### ######### GRAPH 3: Mood during activities ############ ###################################################### #make data frame act_names=c("Sleeping", "Household chores/groceries", "Working/studying", "Doing sports", "Something relaxed", "Hobby", "A trip", "Something together with others","Self-care", "Resting/nothing", "Something intimate", "On the way", "Something else") act_affect1<-c(rtruncnorm(13,a=0, b=100, mean=50,sd=10)) act_aff<-as.data.frame(cbind(act_names,as.numeric(act_affect1))) #define position of categories in the plot act_col<-c("chartreuse", "brown1","blue","yellow","darkgreen","deepskyblue","darkorange", "darkred","darkslategray1","gray44","olivedrab1", "deeppink","turquoise1") #make the plot ggplot(act_aff,aes(act_names,act_affect1))+ geom_bar(stat="identity",fill=rev(rainbow(13)))+ scale_y_continuous(name="Cheerfulness",limits=c(0,100),breaks=c(0,20,40,60,80,100))+ scale_x_discrete(name="",limits=rev(act_aff$act_names))+ labs(x="act_names")+ coord_flip()+ theme(text=element_text(size=20)) #enlarge axis text ###################################################### ########## GRAPH 4: Weekly questionnaires ############ ###################################################### ##mania asrm_val<-c(4, 2, 3, 1, 0, 2, 4, 1, 2, 6, 1, 1, 1, 1,0) asrmdate<-c("May 1 2022", "May 8 2022","May 15 2022",'May 22 2022',"May 29 2022","June 5 2022","June 12 2022", "June 19 2022","June 26 2022","July 3 2022","July 10 2022","July 17 2022","July 24 2022","July 31 2022", "August 7 2022") asrmdate.class<-as.Date(c("2022-05-01","2022-05-08","2022-05-15","2022-05-22","2022-05-29","2022-06-05", "2022-06-12","2022-06-19","2022-06-26","2022-07-03","2022-07-10","2022-07-17", "2022-07-24","2022-07-31","2022-08-07")) asrm_dat<-as.data.frame(cbind(as.numeric(as.character(asrm_val)),asrmdate,asrmdate.class)) #plot asrm scores (mania) ggplot(asrm_dat,aes(rev(asrmdate),asrm_val,group=1))+ geom_line()+ geom_hline(yintercept=5,col="orange")+ geom_point()+ scale_y_continuous(name="Mania",limits=c(0,12),breaks=c(0,2,4,6,8,10,12))+ scale_x_discrete(name="Date",labels=asrmdate)+ theme(axis.title=element_text(size=18))+ theme(axis.text=element_text(angle=90,size=12)) ###depression qids_val<-c(4,6,2,12,19,9,6,7,3,4,3,8,9,7,9) qids_date<-c("May 1 2022", "May 8 2022","May 15 2022",'May 22 2022',"May 29 2022","June 5 2022","June 12 2022", "June 19 2022","June 26 2022","July 3 2022","July 10 2022","July 17 2022","July 24 2022","July 31 2022", "August 7 2022") qids_date.class<-as.Date(c("2022-05-01","2022-05-08","2022-05-15","2022-05-22","2022-05-29","2022-06-05", "2022-06-12","2022-06-19","2022-06-26","2022-07-03","2022-07-10","2022-07-17", "2022-07-24","2022-07-31","2022-08-07")) qids_dat<-as.data.frame(cbind(as.numeric(as.character(qids_val)),qids_date,qids_date.class)) #plot qids_ scores (Depression) ggplot(qids_dat,aes(qids_date.class,qids_val,group=1))+ geom_line()+ geom_hline(yintercept=10,col="orange")+ geom_hline(yintercept=16,col="red")+ scale_y_continuous(name="Depression",limits=c(0,24),breaks=c(0,4,8,12,16,20,24)) + geom_point()+ scale_x_discrete(name="Date",labels=qids_date)+ theme(axis.title=element_text(size=18))+ theme(axis.text=element_text(angle=90,size=12)) ###################################################### ########## GRAPH 5: Sleep & Appointments ############# ###################################################### #create 1ce per day variables set.seed(5) slpqual<-as.numeric(as.character(c(rtruncnorm(100,a=0, b=12, mean=7,sd=2.2)))) slpdur<-as.numeric(as.character(c(rtruncnorm(100,a=0, b=100, mean=40,sd=18)))) slptime<-c(1:100) slpdata<-as.data.frame(cbind(slptime,slpqual,slpdur)) #insert missing c_names1 = c("slpqual", "slpdur") prc_missing1 = 0.24 #corresponding to the 76% compliance rate n_remove1 = prc_missing1*nrow(slpdata) slpdata_mis<-slpdata %>% gather(var,value,-slptime) %>% #reshape data sample_frac(1)%>% group_by(var)%>% mutate(value=ifelse(var%in% c_names&row_number()<=n_remove,NA,value))%>% spread(var,value) #reshape to original format lables.main.slp<-c("time","Sleep duration", "Sleep quality") lables.under.slp<-c("time","0h","very bad") lables.above.slp<-c("time","12h or more","very good") d3<-as.matrix(slpdata_mis) #now we make a massive line graph, plotting the items across all weeks #we also highlight weeks with elevated mania or depression scores for(i in 2:3){ plot(d3[,1], type="o",d3[,i],pch=20,lwd=1.1, main=lables.main.slp[i], xlab="", ylab="", xaxt='n', yaxt='n', ylim=c(0, 12),cex.main=1) mtext(lables.under.slp[i], side=2, line=0.3, adj=0, cex=0.8);mtext(lables.above.slp[i], side=2, line=0.3, adj=1, cex=0.8) #to make grey transparent lines for each week abline(v=slptime[1],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[8],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[15],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[22],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[29],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[36],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[43],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[50],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[57],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[64],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[71],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[78],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[85],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[92],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[99],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[106],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[113],col=adjustcolor("black",alpha.f=0.4));abline(v=slptime[120],col=adjustcolor("black",alpha.f=0.4)); abline(v=slptime[127],col=adjustcolor("black",alpha.f=0.4)); #to assign labels to each week mtext(asrmdate[1], side=1,line=0.3,at=slptime[1],cex=0.8,las=3); mtext(asrmdate[2], side=1,line=0.3,at=slptime[8],cex=0.8,las=3);mtext(asrmdate[3], side=1,line=0.3,at=slptime[15],cex=0.8,las=3); mtext(asrmdate[4], side=1,line=0.3,at=slptime[22],cex=0.8,las=3);mtext(asrmdate[5], side=1,line=0.3,at=slptime[29],cex=0.8,las=3); mtext(asrmdate[6], side=1,line=0.3,at=slptime[36],cex=0.8,las=3);mtext(asrmdate[7], side=1,line=0.3,at=slptime[43],cex=0.8,las=3); mtext(asrmdate[8], side=1,line=0.3,at=slptime[50],cex=0.8,las=3);mtext(asrmdate[9], side=1,line=0.3,at=slptime[57],cex=0.8,las=3); mtext(asrmdate[10], side=1,line=0.3,at=slptime[64],cex=0.8,las=3);mtext(asrmdate[11], side=1,line=0.3,at=slptime[71],cex=0.8,las=3); mtext(asrmdate[12], side=1,line=0.3,at=slptime[78],cex=0.8,las=3);mtext(asrmdate[13], side=1,line=0.3,at=slptime[85],cex=0.8,las=3); mtext(asrmdate[14], side=1,line=0.3,at=slptime[92],cex=0.8,las=3);mtext(asrmdate[15], side=1,line=0.3,at=slptime[99],cex=0.8,las=3); mtext(asrmdate[16], side=1,line=0.3,at=slptime[106],cex=0.8,las=3);mtext(asrmdate[17], side=1,line=0.3,at=slptime[113],cex=0.8,las=3); mtext(asrmdate[18], side=1,line=0.3,at=slptime[120],cex=0.8,las=3);mtext(asrmdate[18], side=1,line=0.3,at=slptime[127],cex=0.8,las=3); #to make lines for depression and mania abline(v=slptime[29],col="darkblue",lwd=3); abline(v=slptime[85],col="red",lwd=3); mtext("Depression",side=3,line=0.3,at=slptime[22],cex=0.8) mtext("(Hypo)mania",side=3,line=0.3,at=slptime[82],cex=0.8) #transparant lines abline(v=slptime[22], col=adjustcolor("blue",alpha.f=0.1),lwd=90); abline(v=slptime[82], col=adjustcolor("red",alpha.f=0.1),lwd=44);} ###################################################### ############# GRAPH 6: Mood variables ################ ###################################################### #plot with kernel smoothing nboot=1000 #SPECIFY number of bootstrap samples for bagging nstable=30 #SPECIFY number of sequential time points that is hypothesized to be stable linemat<-matrix(NA, nrow=nrow(d4), ncol=5) #make empty matrix d4<-as.matrix(simdata_mis) d5<-as.matrix(cbind(simdata$time,simdata$beepno,simdata$date,simdata$dayno,simdata$simvar1,simdata$simvar2,simdata$simvar3,simdata$simvar4,simdata$simvar5)) #again we make massive line graphs, plotting the items across all weeks #we also highlight weeks with elevated mania or depression scores #and we plot a Kernel smoothing line, to show trends in the data for(i in 5:9){ plot(d4[,3], type="l",d4[,i],pch=20,lwd=1.1, main=lables.main[i-1], xlab="", ylab="", xaxt='n', yaxt='n', ylim=c(0, 100),cex.main=1) mtext(lables.under[i-1], side=2, line=0.3, adj=0, cex=0.8);mtext(lables.above[i-1], side=2, line=0.3, adj=1, cex=0.8) #to make grey transparent lines for each week abline(v=date[1],col=adjustcolor("black",alpha.f=0.4));abline(v=date[36],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[71],col=adjustcolor("black",alpha.f=0.4));abline(v=date[106],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[141],col=adjustcolor("black",alpha.f=0.4));abline(v=date[176],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[211],col=adjustcolor("black",alpha.f=0.4));abline(v=date[246],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[281],col=adjustcolor("black",alpha.f=0.4));abline(v=date[316],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[351],col=adjustcolor("black",alpha.f=0.4));abline(v=date[386],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[421],col=adjustcolor("black",alpha.f=0.4));abline(v=date[456],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[491],col=adjustcolor("black",alpha.f=0.4)); #to assign labels to each week mtext(asrmdate[1], side=1,line=0.3,at=date[1],cex=0.8,las=3); mtext(asrmdate[2], side=1,line=0.3,at=date[36],cex=0.8,las=3);mtext(asrmdate[3], side=1,line=0.3,at=date[71],cex=0.8,las=3); mtext(asrmdate[4], side=1,line=0.3,at=date[106],cex=0.8,las=3);mtext(asrmdate[5], side=1,line=0.3,at=date[141],cex=0.8,las=3); mtext(asrmdate[6], side=1,line=0.3,at=date[176],cex=0.8,las=3);mtext(asrmdate[7], side=1,line=0.3,at=date[211],cex=0.8,las=3); mtext(asrmdate[8], side=1,line=0.3,at=date[246],cex=0.8,las=3);mtext(asrmdate[9], side=1,line=0.3,at=date[281],cex=0.8,las=3); mtext(asrmdate[10], side=1,line=0.3,at=date[316],cex=0.8,las=3);mtext(asrmdate[11], side=1,line=0.3,at=date[351],cex=0.8,las=3); mtext(asrmdate[12], side=1,line=0.3,at=date[386],cex=0.8,las=3);mtext(asrmdate[13], side=1,line=0.3,at=date[421],cex=0.8,las=3); mtext(asrmdate[14], side=1,line=0.3,at=date[456],cex=0.8,las=3);mtext(asrmdate[15], side=1,line=0.3,at=date[491],cex=0.8,las=3); #to make lines for depression and mania abline(v=date[141],col="darkblue",lwd=3); abline(v=date[421],col="red",lwd=3); mtext("Depression",side=3,line=0.3,at=date[108],cex=0.8) mtext("(Hypo)mania",side=3,line=0.3,at=date[405],cex=0.8) #transparant lines abline(v=date[108], col=adjustcolor("blue",alpha.f=0.1),lwd=110); abline(v=date[405], col=adjustcolor("red",alpha.f=0.1),lwd=58); ll<- matrix(NA, nrow=length(d5[,3]), ncol=nboot) #bootstrap loop for(j in 1:nboot){ bootsample<-d5[sample(nrow(d5),size=length(d5[,3]),replace=TRUE),] #taking bootstrap samples bootsample<-bootsample[order(bootsample[,3]),] #ordering the bootstrap samples by time lo<-loess(bootsample[,i]~d5[,3], span=(nstable/length(d5[,3])), degree=1, family="symmetric") ll[,j]<-lo$fitted } lines(d5[,3], apply(ll,1,mean), col="red", lwd=2) #robust bagged loess line #create a matrix with the bootstrapped lines linemat[,i-4]<-apply(ll,1,mean)} ###################################################### ########### GRAPH 7: Indicator variables ############# ###################################################### #in the last step we created a matrix with the bootstrapped lines #now we save them in a dataframe, so we can plot the Kernel lines seperately datline<-as.data.frame(linemat) datline$date<-simdata_mis$date #this 'participant' had no indicators for depression, but did show indicators for (hypo)mania #create the plot plot(datline[,3]~datline$date,type="l", xlab="", ylab="", xaxt='n', yaxt='n',ylim=c(0,100),col="deeppink1",lwd=3,cex.main=1) lines(datline[,4]~datline$date,col="orange",lwd=3) lines(datline[,5]~datline$date,col="chartreuse3",lwd=3) #to make grey transparent lines for each week abline(v=date[1],col=adjustcolor("black",alpha.f=0.4));abline(v=date[36],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[71],col=adjustcolor("black",alpha.f=0.4));abline(v=date[106],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[141],col=adjustcolor("black",alpha.f=0.4));abline(v=date[176],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[211],col=adjustcolor("black",alpha.f=0.4));abline(v=date[246],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[281],col=adjustcolor("black",alpha.f=0.4));abline(v=date[316],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[351],col=adjustcolor("black",alpha.f=0.4));abline(v=date[386],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[421],col=adjustcolor("black",alpha.f=0.4));abline(v=date[456],col=adjustcolor("black",alpha.f=0.4)); abline(v=date[491],col=adjustcolor("black",alpha.f=0.4)); #to assign labels to each week mtext(asrmdate[1], side=1,line=0.3,at=date[1],cex=0.8,las=3); mtext(asrmdate[2], side=1,line=0.3,at=date[36],cex=0.8,las=3);mtext(asrmdate[3], side=1,line=0.3,at=date[71],cex=0.8,las=3); mtext(asrmdate[4], side=1,line=0.3,at=date[106],cex=0.8,las=3);mtext(asrmdate[5], side=1,line=0.3,at=date[141],cex=0.8,las=3); mtext(asrmdate[6], side=1,line=0.3,at=date[176],cex=0.8,las=3);mtext(asrmdate[7], side=1,line=0.3,at=date[211],cex=0.8,las=3); mtext(asrmdate[8], side=1,line=0.3,at=date[246],cex=0.8,las=3);mtext(asrmdate[9], side=1,line=0.3,at=date[281],cex=0.8,las=3); mtext(asrmdate[10], side=1,line=0.3,at=date[316],cex=0.8,las=3);mtext(asrmdate[11], side=1,line=0.3,at=date[351],cex=0.8,las=3); mtext(asrmdate[12], side=1,line=0.3,at=date[386],cex=0.8,las=3);mtext(asrmdate[13], side=1,line=0.3,at=date[421],cex=0.8,las=3); mtext(asrmdate[14], side=1,line=0.3,at=date[456],cex=0.8,las=3);mtext(asrmdate[15], side=1,line=0.3,at=date[491],cex=0.8,las=3); #to make lines for depression and mania abline(v=date[141],col="darkblue",lwd=3); abline(v=date[421],col="red",lwd=3); mtext("Depression",side=3,line=0.3,at=date[108],cex=0.8) mtext("(Hypo)mania",side=3,line=0.3,at=date[405],cex=0.8) #transparant lines abline(v=date[108], col=adjustcolor("blue",alpha.f=0.1),lwd=110); abline(v=date[405], col=adjustcolor("red",alpha.f=0.1),lwd=58); #legend legend("topleft",c("Agitated","Easily distracted","Thoughts racing"), lty=c(1,1), lwd=2,col=c("deeppink1","orange","chartreuse3")) ###################################################### ######### GRAPH 8: VAR models (optional) ############# ###################################################### #generate stationary variables phys.act<-rtruncnorm(500,a=0, b=100, mean=33,sd=22) cheerful<-rtruncnorm(500,a=0, b=100, mean=49,sd=17) #check SDs >10 sd(as.numeric(as.character(phys.act)),na.rm=T) sd(as.numeric(as.character(cheerful)),na.rm=T) #stationarity check plot(as.numeric(as.character(phys.act)),type="l") plot(as.numeric(as.character(cheerful)),type="l") #save the variables in a dataframe autovarmod<-as.data.frame(cbind(phys.act,cheerful)) colnames(autovarmod)[1:2]<-c("active","cheerful") #run the autovarCore models models_found<-autovar(ef_nee, selected_column_names = c("active","cheerful"), significance_levels = c(0.05,0.01,0.005), #default test_names = c('portmanteau', 'portmanteau_squared', 'skewness'), #default criterion = 'AIC', #default imputation_iterations = 30, #default measurements_per_day=5) #check all models for their significance values summary(models_found[[1]]$varest) summary(models_found[[2]]$varest) summary(models_found[[3]]$varest) summary(models_found[[4]]$varest)