2
0

head.R 1000 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. remove(i)
  12. #Check if patient is walking fast enough
  13. differ_ <- 0.5
  14. # Algorithm to calculate walk phase
  15. f <- function(x) (sin((x - 5) / 2.7) / 30) + patient$WALKBASE
  16. # Draw Optimum walk
  17. lines(patient$WALKING, f(patient$WALKING), col = "orange", type = "l")
  18. # Check if each point is close to optimum track
  19. WALK <- data.frame(index=patient$WALKING)
  20. WALK$probability <- 0
  21. for(i in patient$WALKING){
  22. prob_ <- 1 - abs((abs(DATA[i,]$Head.y - f(i))) / differ_)
  23. WALK[WALK$index==i,]$probability <- if(prob_ > 1) 1 else if(prob_ < 0) 0 else prob_
  24. }
  25. remove(i)
  26. remove(prob_)
  27. # Print out possible fall chance
  28. print(paste("FALL CHANCE BASED ON STEPS: ", as.character(specify_decimal(100-(mean(WALK$probability)*100), 2)), "%", sep = ""))
  29. print("DONE ANALYZING HEAD")