Step count algorithm for GGIR

1,614 views
Skip to first unread message

Matt Patterson

unread,
Jul 13, 2020, 10:27:54 AM7/13/20
to R package GGIR
Hi GGIR Users,

The team at Verisense have created a step counter to work with GGIR.

The algorithm works with the external function capability of GGIR 2.0.

Here is the link to the algorithm and the documentation to use it - link.

The step count per day outputs are added to the 'part2_daysummary.csv' outputs.

Feel free to contact me if you run into any troubles implementing it, or have any comments or feedback.

Take care,

Matthew Patterson
Biomedical Data Scientist


Message has been deleted

Jean-Benoît Rossel

unread,
Mar 23, 2021, 8:46:51 AM3/23/21
to R package GGIR
Dear Matthew,
Dear GGIR and Verisense Step Count Algorithm users,

Thank you very much for your work and for your step counter.

I work as a statistician at the Clinical Trials Unit from the University of Bern, Switzerland. In particular, I work on a project where 380 hospitalized patients have to wear tri-axis accelerometer (GENEActiv Original), parametrized at 50 Hz. We want to measure the time they spent on different activity levels. I can use GGIR for that. Please note that I never heard about accelerometer data nor GGIR before starting this project, so I am a complete neophyte.

We are also interested in patients' number of steps taken per day, mean cadence and maximum gait speed. I was very interested in Verisense Step Count Algorithm for this task, in particular for its compatibility with GGIR.

I followed your "ReadMe" file, without modifying your R scripts. Then, in the "part2_daysummary.csv" file, I obtained some values for only 2 days (and 1 patient)! The other 2552 lines of the column "step_count_sum_0-24hr" are empty.

I put my "g.shell.GGIR" code below. Would you have any idea why the script failed to calculate the number of steps of all other patients?

Thank you in advance for your help!

Best regards,


Jean-Benoît Rossel



g.shell.GGIR  (#-------------------------------
               # General parameters
               #-------------------------------
               mode=c(1:5),
               datadir=datadir,
               outputdir=outputdir,
               studyname=studyname,
               f0=1,
               f1=c(),
               overwrite=TRUE,
               do.imp=TRUE,
               idloc=1,
               print.filename=TRUE,
               storefolderstructure = FALSE,
               #-------------------------------
               # Part 1 parameters:
               #-------------------------------
               windowsizes = c(5,900,3600),
               #deziredtz="Europe/Bern",
               do.cal=TRUE,
               do.enmo = TRUE,
               do.anglez=TRUE,
               chunksize=1,
               printsummary=TRUE,
               #-------------------------------
               # Part 2 parameters:
               #-------------------------------
               strategy = 1,
               ndayswindow=14,
               hrs.del.start=1,
               hrs.del.end=2,
               maxdur = 15,
               includedaycrit=10,
               L5M5window = c(0,24),
               M5L5res = 10,
               winhr = c(5),
               qlevels = c(c(1380/1440),c(1410/1440)),
               qwindow=c(0,24),
               ilevels = c(seq(0,400,by=50),8000),
               mvpathreshold =c(182),
               #-------------------------------
               # Part 3 parameters:
               #-------------------------------
               timethreshold= c(5),
               anglethreshold=5,
               ignorenonwear = TRUE,
               #-------------------------------
               # Part 4 parameters:
               #-------------------------------
               excludefirstlast = FALSE,
               includenightcrit = 10,
               def.noc.sleep = c(21,9),
               #loglocation= "pathname to a sleeplog - if using one",
               outliers.only = FALSE,
               criterror = 4,
               relyonsleeplog = FALSE,
               sleeplogidnum = TRUE,
               colid=1,
               coln1=2,
               do.visual = FALSE,
               nnights = 14, 
               #-------------------------------
               # Part 5 parameters:
               #-------------------------------
               # Key functions: Merging physical activity with sleep analyses
               threshold.lig = c(30,85),
               threshold.mod = c(100,181),
               threshold.vig = c(400,437),
               boutcriter = 0.8,
               boutcriter.in = 0.9,
               boutcriter.lig = 0.8,
               boutcriter.mvpa = 0.8,
               boutdur.in = c(10),
               boutdur.lig = c(10),
               boutdur.mvpa = c(10),
               timewindow = c("WW"),
               #-------------------------------------------
               # Report generation, including step counts
               #-------------------------------------------
               do.report=c(2:5),
               myfun = myfun)


Matt Patterson

unread,
Mar 23, 2021, 9:13:37 AM3/23/21
to Jean-Benoît Rossel, R package GGIR
Hi Jean-Benoît,

That doesn't sound very good. By the looks of your entry function, everything should be working fine. 

You should double check that the source path and the function name are correct in your 'myscript.R' function. The source path should go to the local instance of 'verisense_count_steps.R' on your machine and the first element in the myfun list should be the name 'verisense_count_steps'. Previous versions of code used a different name and the script wasn't called correctly. These refer to lines 1 and 2 in the following image:
image.png
Also, be sure to keep expected_sample_rate at 15, do not change it to 50.

Let me know if any of this helps, otherwise, if you can send me a file in which it doesn't work I can have a deeper look at the problem.

Good luck,

Matt





--
You received this message because you are subscribed to the Google Groups "R package GGIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to RpackageGGIR...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/RpackageGGIR/bce5445c-3c76-42a9-9d8e-a07091bec3can%40googlegroups.com.

Jean-Benoît Rossel

unread,
Mar 23, 2021, 3:20:03 PM3/23/21
to R package GGIR
Dear Matt,

Thank you very much for your quick reply! I followed your advices but unfortunately, the situation did not improve.

I realize that my "part2_daysummary.csv" file contains a lot of empty cells, in particular between column I ("L5hr_ENMO_mg_0-24hr") to column AE ("MVPA_E5S_B10M80%_T182_ENMO_0-24hr"). Almost all patients have at least one line with all these cells empty. Maybe there is something problematic with the values I chose in "g.shell.GGIR" function, which makes computation of these values impossible, as well as the computations with your step count algorithm. I will try again with other values.

I will send you a compressed folder with the bin-file of one patient. Thank you in advance for having a look on it!

Best regards,
Jean-Benoît

ben_m...@hotmail.com

unread,
Apr 12, 2021, 4:13:11 AM4/12/21
to R package GGIR
Hi Jean-Benoit and Matthew,

Firstly, Thank you for sharing this Matthew - It was easy to understand and I got it working first time. I really appreciate you making this available and for your time spent on it.
 
I just wanted to chip in and say that I got this to work over the weekend on some data fine using the below part 1 and 2 parameters, and just running mode 1:2.

#-------------------------------
# Part 1 parameters:
#-------------------------------
windowsizes = c(5,900,3600), 
do.cal=TRUE,
do.enmo = TRUE, 
do.anglez=TRUE,
chunksize=1,
printsummary=TRUE,
#-------------------------------
# Part 2 parameters:
#-------------------------------
strategy = 1,
ndayswindow=1,
hrs.del.start = 0,
hrs.del.end = 0,
maxdur = 9,
includedaycrit = 16, 
M5L5res = 10,
winhr = c(c(960/60),c(600/60),c(480/60),c(300/60)),
M5L5 = c(0.1,0.25,0.5,0.75,0.9),
iglevels = TRUE,
qlevels = c(c(480/1440),c(720/1440),c(840/1440),c(960/1440),c(1080/1440),c(1200/1440),c(1320/1440),c(1380/1440),c(1410/1440),c(1420/1440),c(1425/1440),c(1430/1440),c(1435/1440),c(1438/1440),c(1439/1440)), 
qwindow=c(0,24), 
ilevels = c(0,100,400,8000), 
mvpathreshold =c(100,250,400), 
boutcriter = c(0.8),
mvpadur = c(1,5,10),
bout.metric = 4,
closedbout = FALSE,
#-----------------------------------
# Report generation
#-------------------------------
do.report=c(2),
visualreport=TRUE,
dofirstpage = TRUE,
viewingwindow=1,
myfun = myfun)


Kind regards,
Ben

Matt Patterson

unread,
Apr 14, 2021, 2:33:07 PM4/14/21
to ben_m...@hotmail.com, R package GGIR
There is now an updated version of the step counter online (link).

It seems that the algorithm was crashing when there were multiple days of non-wear in a trial. This is now fixed, so anyone who was having problems with the steps algorithm should try out the new one to see if it solves the problem.

If problems persist, please email back to the group.

Matt



--
You received this message because you are subscribed to the Google Groups "R package GGIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to RpackageGGIR...@googlegroups.com.

Jean-Benoît Rossel

unread,
Apr 19, 2021, 2:21:19 PM4/19/21
to R package GGIR
Dear Matt,

Thank you very much for having fixed this bug. There is indeed a lot of non-wear and inactivity in my data with hospitalized patients.

Unfortunately, I still obtain some results for only 1 patient among 380. This patient has two days of data. I will try Ben's coefficients to see if it works better.

Best regards,
J-B

Muhammad Alif Bin Abu Bakar

unread,
Feb 16, 2023, 10:38:06 PM2/16/23
to R package GGIR
Hi Matt,

I'm Alif, a Masters student. My supervisors have tasked me to look into understanding and integrating verisense step counts into GGIR version 2.8.2 on RStudio 4.2.2. I keep getting object 'myfun' not found error. I did follow the instructions from your link. Below is my script.

library(GGIR)
GGIR(#---------------------------------------
             # General parameters:
             #-------------------------------
             mode= c(1,2,5),
             datadir= datadir,
             outputdir= outputdir,
             epochvalues2csv= TRUE,
             do.parallel= FALSE,
             myfun= myfun,

             #-------------------------------
             # Part 1 parameters:
             #-------------------------------
             windowsizes = c(5,900,3600),
             do.cal=TRUE,
             do.enmo = TRUE,
             acc.metric= "ENMO",

             do.anglez=TRUE,
             chunksize=1,
             printsummary=TRUE,
             #-------------------------------
             # Part 2 parameters:
             #-------------------------------
             strategy= 1,
             hrs.del.start= 0, hrs.del.end= 0,
             maxdur= 8, includedaycrit= 16,
             qwindow= c(6,24),
             mvpathreshold= c(192),
             bout.metric= 4,

             #-------------------------------
             # Part 5 parameters:
             #-------------------------------
             threshold.lig= c(56),
             threshold.mod= c(192),
             threshold.vig= c(695),
             boutcriter= 0.8,      
             boutcriter.in= 0.9,    
             boutcriter.lig= 0.8,
             boutcriter.mvpa= 0.8,
             boutdur.in= c(1,5,10),
             boutdur.lig= c(1,5,10),
             boutdur.mvpa= c(1,5,10),
             includedaycrit.part5= 2/3,
             minimum_MM_length.part5= 16,
             #-------------------------------
             # Report generation
             #-------------------------------
             # Key functions: Generating reports based on meta-data
             do.report= c(2,5),
             dofirstpage= TRUE,
             visualreport= TRUE,
             viewingwindow= 1)

When the line myfun= myfun is removed. Everything get processed with no issues. I would greatly appreciate your kind assistance in this matter.

Regards,
Muhammad ALIF

Matt Patterson

unread,
Feb 17, 2023, 9:06:26 AM2/17/23
to Muhammad Alif Bin Abu Bakar, R package GGIR
Hi Muhammad,

You have to 'source' the 'myscript.R' function before you make the GGIR call. This is step 4 in the instructions. Make sure that you follow steps 1-3 as well, set the right path to the local version of 'verisense_count_steps.R' on your machine.

Matt

Muhammad Alif Bin Abu Bakar

unread,
Feb 22, 2023, 7:52:27 PM2/22/23
to R package GGIR
Hi Matt, 

It's all good, the data along with step counts were processed!! Thank you so much for the help, i really appreciate it.

Regards,
Muhammad ALIF

Message has been deleted

Matt Patterson

unread,
Apr 14, 2023, 2:41:09 PM4/14/23
to Elena Mathieu, R package GGIR
Hi Elena,


A recent paper proposed updated parameters on a larger data-set - https://www.mdpi.com/1424-8220/22/24/9984

All the best, Matt



On Tue, Apr 11, 2023 at 2:31 AM 'Elena Mathieu' via R package GGIR <Rpacka...@googlegroups.com> wrote:
Hi Matt

I could implement the verisense algorithmus - thank you very much for this. One question is still there: How have you chosen the numbers in the myfun command? You shared an image with parameters = c(3, 5, 15, ...) but where are this numbers from? Probably you could send me a link to a website, where this is all explained. I could not find any one.

Kind regards,
Elena

Elena Mathieu

unread,
Apr 18, 2023, 10:50:48 AM4/18/23
to R package GGIR
Hi Matt

Thank you for your answer. Now I have another one. Is it possible to implement your verisense algorithme for different day segements? With GGIR you can do day segmentation with qwindow. Is it possible to get the number of steps for example the daysegment work?

Best,
Elena

marcuslop...@gmail.com

unread,
Apr 18, 2023, 11:04:09 AM4/18/23
to R package GGIR
Hi Elena,

I just tested this myself, but Matt may be able to confirm if such outputs are valid. 
By including the Verisense algorithm in the "myfun" argument, the step counts will be computed for all segments defined with qwindow.  The variables will be named as "step_count_sum_8.12hr" for a segmentation referring to the interval between 8AM and 12PM, for example.

Best,
Marcus

Olivier Turcotte

unread,
Nov 18, 2023, 3:56:32 AM11/18/23
to R package GGIR
Hi Matt,
I tried to run the Verisense 2 algorithm and everything seemed ok. Then I checked the  "part2_daysummary.csv" and I didn't find the steps variables. I thought that the part2 could be run when the milestone data of part1 was calculated so overwrite = FALSE. Am I wrong?
Thanks

Here are my parameters:

do.report = c(2,4,5),
  overwrite = FALSE,
  #=====================
  # Part 2
  #=====================
  strategy = 1, 

  hrs.del.start = 0,        
  hrs.del.end = 0,           
  maxdur = 0,                 
  includedaycrit = 16,         
  winhr = c(5,10),            
  qwindow=c(0,24),             
  mvpathreshold =c(100),     
  excludefirstlast = FALSE,    
  includenightcrit = 16,       
  myfun = myfun,               
  #=====================
  # Part 3 + 4
  #=====================
  def.noc.sleep = 1,           
  outliers.only = FALSE,       
  criterror = 3,               
  do.visual = FALSE,           
  HASPT.algo = "HDCZA",        
  HASIB.algo = "vanHees2015",  
  #=====================
  # Part 5
  #=====================
  threshold.lig = c(40),      
  threshold.mod = c(100),     
  threshold.vig = c(400),     

  boutcriter = 0.8,      
  boutcriter.in = 0.9,         
  boutcriter.lig = 0.8,        
  boutcriter.mvpa = 0.8,       
  boutdur.in = c(10,20,30),    
  boutdur.lig = c(1,5,10),     
  boutdur.mvpa = c(1,5,10),    
  includedaycrit.part5 = 2/3,  
  #=====================
  # Visual report
  #=====================
  timewindow = c("MM"),        
  visualreport=TRUE) 
         

Vincent van Hees

unread,
Nov 18, 2023, 7:37:29 AM11/18/23
to Olivier Turcotte, R package GGIR
The step detection is applied in GGIR part 1, so you will need to overwrite the previously generated part 1 output (mode = 1, overwrite = TRUE). Summarising of step data happens in part 2, so also that part needs to be re-run.

Vincent

Tin GOJEVIC

unread,
Jan 26, 2024, 9:09:37 AM1/26/24
to R package GGIR
Great work Matt and thank you for the script! Any idea on how it performs with a hip-worn accelerometer? - I use actigraphs gt3x on the hip and was searching for a script for steps...

Thank you and best regards,
Tin

Anne Backes

unread,
Jan 20, 2025, 1:34:35 AMJan 20
to R package GGIR

Hi Matt,

Thank you very much for making the step count algorithm publicly available.

Regarding your explanation above, I was curious about why the sampling frequency should remain fixed at 15Hz rather than being adjusted to the actual sampling frequency.
Does this also apply to line 10 in the verisense_count_steps.R script: “fs = 15 # temporary for now, this is manually set”?

Thank you in advance!

Best regards,

Anne


Matt Patterson schrieb am Dienstag, 23. März 2021 um 14:13:37 UTC+1:

kraf...@gmail.com

unread,
Jun 11, 2025, 10:41:24 AMJun 11
to R package GGIR
Hi Anne,

Is there any chance that you got a direct reply from Matt on this topic? In the implementation of the "walking" package for this algorithm, the documentation would suggest that a user might enter their device sampling rate, rather than the default 15 Hz (https://github.com/muschellij2/walking/blob/86c13bb7c0fbf9afabe045fcdae493b273b10201/R/verisense_count_steps.R#L159).

Tom

Vincent van Hees

unread,
Jun 11, 2025, 11:43:38 AMJun 11
to kraf...@gmail.com, Anne Backes, R package GGIR
Hi Tom,

I cc-ed Anne for your convenience.

I doubt Matt or Anne have seen these messages as google group does not send notifications when  someone replies to a thread. So, the only way for them to have noticed the correspondence is by frequently check the google group. 

On that note - I am planning to promote GitHub discussion as a platform for GGIR Q&A as opposed to this google group, but more about that in a future message. Feel free to keep using the google group for the time being.

Best,

Vincent

Reply all
Reply to author
Forward
0 new messages