Skip to content

Commit

Permalink
added readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniela Gawehns committed Jan 25, 2024
1 parent 2af63ac commit 893c83d
Show file tree
Hide file tree
Showing 40 changed files with 165 additions and 19 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion AnalysisPipelineSTART_HERE.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Data24hrs21<- normalize24hrs30min(perPerson21)
### For 2021: Medlo, 24hrs, estimators (MAD and ENMO)
MedloData <- NormalizedTo30min #
Normalized_24hrs_Data <- Normalized24hrsTo30min21 #
keydata<- Link19_21
keydata<- Link19_21 [,1:2]

### create linkedData for different ENMO/MAD epochs to compare results

Expand All @@ -128,6 +128,7 @@ Frag=sapply(MAD_AllEpochs5sec,fragment),
#time spend above 100 (relative)
Rel= sapply(MAD_AllEpochs5sec, function (x) length(which(x >100))) )

#create dataset for correlation matrix (this means some data will be lost bc only complete sets are kept!)
LinkedData_21_5sec<- link21data (MedloData, Normalized_24hrs_Data, ENMO_MAD_Data, keydata)


Expand Down
Binary file added BarchartPercentagesMedlo.pdf
Binary file not shown.
Binary file added BoxplotAllCatsMedlo.pdf
Binary file not shown.
Binary file added BoxplotAllCatsSamsung.pdf
Binary file not shown.
Binary file added BoxplotAllCatsSamsungPercent.pdf
Binary file not shown.
Binary file added BoxplotsAllCatsSamsung.pdf
Binary file not shown.
Binary file modified CorrelationMatrix_5sec.pdf
Binary file not shown.
Binary file modified CorrelationMatrix_5sec_hc.pdf
Binary file not shown.
20 changes: 13 additions & 7 deletions LinkData_Correlations.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@ link21data<- function (MedloData, Normalized_24hrs_Data, ENMO_MAD_Data, keydata)
WatchData_21 <- merge(SensorData_21,Dat21_24hrs, by = "ResidentID" )

#Sensors, 24hrs, Medlo in 21
MovementData_21 <- merge(WatchData_21, MedloData, by.x = "NIVEL.ID..Compas.2019.", by.y = "bwcode")
MovementData_21 <- MovementData_21[,-c(13,14,15,16,17)] #remove empty cols from keyfile and an empty column for "cycling"
MovementData_21 <- merge(WatchData_21, MedloData, by.x = "NIVEL.ID..Compas.2019.", by.y = "bwcode") #this is where "cycling" disappears
#(only full observations are kept - for correlations later)

#MovementData_21 <- MovementData_21[,-c(21,22,23,24)] #remove empty cols from keyfile - not needed anymore, cleaned keyfile when importing data

colnames(MovementData_21) <- c( "NIVEL_ID", "LIACS_ID",
"MeanMAD", "MeanEN", "MeanENMO",
"MADmean", "MeanEN", "MeanENMO",
"MinMAD","MinEN", "MinENMO",
"MaxMAD", "MaxEN", "MaxENMO",
"VarMAD", "VarEN", "VarENMO",
"NoEpochs",
"Inactive", "Light",
"MADsd", "MADmedian", "MADqant", "MADfrag","MADrel",
"Cycling","Inactive", "Light",
"NotOnWrist", "Sleeping",
"MLO1", "MLO2", "MLO3", "MLO4", "MLO5",
"MLO6", "MLO7")

#select a subset of entries for correlation matrix:
data<- MovementData_21[, c(3,5,7,
13,14,15,16,
17,18,19,20,21,22) ]
data<- MovementData_21[, c(3, #MADmean
16,17,18,19,20, #sd,median, qant,frag,rel
22,23,24,25, #inactive, light, sleeping, not on wrist
26,27,29,30) ]#ml1,ml2,ml4, ml5
data[is.na(data)] <- 0

return(data)
Expand Down
Binary file added MADSpreadHighVariance.pdf
Binary file not shown.
Binary file added MADSpreadHighVariance0to420.pdf
Binary file not shown.
Binary file added MADSpreadHighestVariance.pdf
Binary file not shown.
Binary file added MADSpreadLowVariance0to420.pdf
Binary file not shown.
Binary file added MADSpreadLowestvariance.pdf
Binary file not shown.
Binary file added MADspreadHighVariance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MADspreadLowVariance.pdf
Binary file not shown.
Binary file added PerResidentMAD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMAD5sec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PerResidentMADResidentID9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PercentageTimeMedloActive.pdf
Binary file not shown.
Binary file added PercentageTimeSamsungActive.pdf
Binary file not shown.
114 changes: 103 additions & 11 deletions PlottingScripts.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Plotting Scripts
Plotting Scripts

##############################
#Barcharts - MEDLO and 24hrs data
Expand All @@ -11,7 +11,7 @@ datMedlo <- data.frame(
"Standing", "Standing activity/walking around", "Walking Activity/Cycling",
"Sports/Whole Body Movement")),

TimeSumsMedlo = c(colSums(LinkedData_21_30min [,8:13], na.rm = TRUE),0)
TimeSumsMedlo = c(colSums(LinkedData_21_5sec [,8:13], na.rm = TRUE),0)
)

p <- ggplot(data=datMedlo, aes(x=MovementCategoryMedlo, y=TimeSumsMedlo, fill=MovementCategoryMedlo)) +
Expand Down Expand Up @@ -71,9 +71,10 @@ corrplot(cor(LinkedData_21_5sec),
#lower = "number",
#upper = "circle",
tl.col = "black",
title = "5secEpochs",
title = "",
mar=c(0,0,2,0),
order = "hc",
order = "hclust",
hclust.method = "complete",
addrect = 2)

# Closing the graphical device
Expand Down Expand Up @@ -112,24 +113,115 @@ pairs(LinkedData_21_60sec[,c(4,5,6,7,8,9,10,11,12,13)], pch = 19)

MAD_AllEpochs5sec<-readRDS("epochsPerResident5sec.rds")
allData<-numeric(length=3)
allMeans<-numeric()

for (i in 1:length(MAD_AllEpochs5sec)){

dat<-data.frame(MAD=MAD_AllEpochs5sec[[i]],
time= seq (1: length( MAD_AllEpochs5sec[[i]])),
resident=rep(i, length(MAD_AllEpochs5sec[[i]])))
dat<-data.frame(MAD=MAD_AllEpochs5sec[[i]][,1],
measurement= seq (1: length( MAD_AllEpochs5sec[[i]][,1])),
resident=rep(i, length(MAD_AllEpochs5sec[[i]][,1])))

allData<-rbind(allData,dat)
allMeans<-c(allMeans, mean(dat$MAD,na.rm=TRUE))
}

allData<- allData [-1,] #remove empty first line
var(allMeans)
min(allMeans)
max(allMeans)
#########




library(ggplot2)
allData<- allData [-1,]
ggplot(allData, aes(time, MAD)) +
###! This takes a long time to render!
p<- ggplot(allData, aes(x=measurement, y=MAD)) +
geom_point()+
facet_wrap(~allData$resident, nrow=3)
p
ggsave(filename="PerResidentMAD.png")

#####This is more doable,saves plots individually
for (j in 1:length(unique(allData$resident))) {
filename <- paste0("PerResidentMADResidentID",j,".png")
sampleResident <- allData[which(allData$resident == j),]
q<-ggplot(sampleResident, aes(x=measurement, y =MAD)) + geom_point()
q
ggsave(filename)
}

lowvarianceResIDs<- c(6,2,15)
highvarianceResIDs<- c(8,14,13)

p<- ggplot(allData [which(allData$resident %in%lowvarianceResIDs),],
aes(x=measurement, y=MAD)) +
geom_point()+
facet_wrap(~allData$resident, nrow=3)
ylim(0,420)+
facet_wrap(~allData [which(allData$resident %in%lowvarianceResIDs),]$resident,
nrow=1)
p
ggsave("MADSpreadLowVariance0to420.pdf")

p <- ggplot(allData, aes(x=as.factor(allData$resident), y=MAD)) +
q<- ggplot(allData [which(allData$resident %in%highvarianceResIDs),],
aes(x=measurement, y=MAD)) +
geom_point()+
ylim(0,420)+
facet_wrap(~allData [which(allData$resident %in%highvarianceResIDs),]$resident,
nrow=1)
q
ggsave("MADSpreadHighVariance0to420.pdf")

#### violin plots of MAD data per resident
p <- ggplot(allData [which(allData$resident %in%lowvarianceResIDs),],
aes(x=as.factor(allData [which(allData$resident %in%lowvarianceResIDs),]$resident),
y=MAD)) +
geom_violin()
p

#############################
#instead of barcharts of the summed data, make boxplots of the percentage of time
#a resident spend in one movement category

Medlo_2019$codebew

percentageActiveMedlo21<- MedloData [1:13 ,2:8] * 100/30 #!!! Use on first 13 entries for 2021 entries
percentageActiveMedlo21[is.na(percentageActiveMedlo21)] <- 0 #clear NAs

percentageActiveSamsungCat<- t(Normalized_24hrs_Data) *100/30
percentageActiveSamsungCat[is.na(percentageActiveSamsungCat)] <- 0 #clear NAs

percentageActiveMedloLong21<- data.frame(
percentage=unlist(c(percentageActiveMedlo21)),
activity=c(rep("ML01", 13), rep("ML02", 13),
rep("ML03", 13),
rep("ML04", 13), rep("ML05", 13),
rep("ML06", 13), rep("ML07", 13))
)

percentageActiveSamsungLong<- data.frame(
percentage=unlist(c(percentageActiveSamsungCat)),
activity=c(rep("Cycling", 16), rep("Inactive", 16),
rep("Light", 16),
rep("NotOnWrist", 16), rep("Sleeping", 16) )
)

boxplot(percentageActiveMedloLong21$percentage ~ percentageActiveMedloLong21$activity,
col='steelblue',
main='Percentage of Time spent per activity',
xlab='Activity',
ylab='Percentage of Time')

# Opening the graphical device
pdf("BoxplotAllCatsSamsungPercent.pdf")
boxplot(percentageActiveSamsungLong$percentage ~ percentageActiveSamsungLong$activity,
col='steelblue',
main='Percentage of Time spent per activity',
xlab='Activity',
ylab='Percentage of Time')

# Closing the graphical device
dev.off()



Binary file modified epochsPerResident5sec.rds
Binary file not shown.
47 changes: 47 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Using Consumer Wearables to Measure Physical Activity of Nursing Home Residents with Dementia

This is the repository with the code needed to rerun our analysis of the manuscript: "Using Consumer Wearables to Measure Physical Activity of Nursing Home Residents with Dementia", available as preprint here: https://osf.io/preprints/psyarxiv/mqg86


## Data

The data necessary to run this script and to recreate the plots is currently not available.
There are three types needed
a) aggregated behavioral observations (Medlo Data)
b) raw accelerometer data (Acc Data)
c) aggregated 24hrs log data from the Samsung activity recognition application (24hrs Data)

From the raw accelerometer data one can calculate the MAD derivatives.
With the two aggregated datasets the correlation matrix can be recreated


__Data Contact__

You can contact Daniela Gawehns, the owner of the repro and first author of the manuscript regarding the data: <gawehnsd@liacs.leidenuniv.nl> or <d.gawehns@umcg.nl>


## Getting Started

The .r file named AnalysisPipelineSTART_HERE.R is the easiest entry point to rerun the analysis. This is where the data gets imported, cleaned and normalized into the format used for the plots.
The file PlottingScripts.R contains all code used to plot the figures in the manuscript.


### Requirements

The scrips have the following dependencies: ggplot2, lubridate, haven and eeptools
(eeptools is only used in a script to extract demographic data from participant files, which will not be shared out of privacy reasons)

## Publications

Gawehns, D., Portegijs, S., van Beek, A. P. A., & van Leeuwen, M. (2024, January 26). Using Consumer Wearables to Measure Physical Activity of Nursing Home Residents with Dementia. Retrieved from osf.io/preprints/psyarxiv/mqg86


van Dijk, R.M.K., Gawehns, D. and van Leeuwen, M., 2023. WEARDA: Recording Wearable Sensor Data for Human Activity Monitoring. Journal of Open Research Software, 11(1), p.13.DOI: https://doi.org/10.5334/jors.454



## License

This project is licensed under CC-BY-SA-4.0.


0 comments on commit 893c83d

Please sign in to comment.