head.R 967 B

123456789101112131415161718192021222324252627282930313233343536
  1. print("START ANALYZING HEAD")
  2. color <- c("red", "blue", "blue", "green")
  3. #Plot graph
  4. plot(DATA$Head.y,
  5. type = "l",
  6. ylab = "Hoogte hoofd"
  7. )
  8. for(i in 1:nrow(DATA)){
  9. points(i, DATA[i,]$Head.y, col = color[DATA[i,]$state])
  10. }
  11. #Check if patient is walking fast enough
  12. differ_ <- 0.5
  13. # Algorithm to calculate walk phase
  14. f <- function(x) (sin((x - 5) / 2.7) / 30) + patient$WALKBASE
  15. # Draw Optimum walk
  16. lines(patient$WALKING, f(patient$WALKING), col = "orange", type = "l")
  17. # Check if each point is close to optimum track
  18. WALK <- data.frame(index=patient$WALKING)
  19. WALK$probability <- 0
  20. for(i in patient$WALKING){
  21. prob_ <- 1 - abs((abs(DATA[i,]$Head.y - f(i))) / differ_)
  22. WALK[WALK$index==i,]$probability <- if(prob_ > 1) 1 else if(prob_ < 0) 0 else prob_
  23. }
  24. # Print out possible fall chance
  25. print(paste("FALL CHANCE BASED ON STEPS: ", as.character(specify_decimal(100-(mean(WALK$probability)*100), 2)), "%", sep = ""))
  26. print("DONE ANALYZING HEAD")