head.R 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. print("START ANALYZING HEAD")
  2. #color <- rainbow(length(STATE))
  3. color <- c("red", "blue", "blue", "green")
  4. #Plot graph
  5. plot(DATA$Head.y,
  6. type = "l",
  7. ylab = "Hoogte hoofd"
  8. )
  9. for(i in 1:nrow(DATA)){
  10. points(i, DATA[i,]$Head.y, col = color[DATA[i,]$state])
  11. }
  12. #Check if patient is walking fast enough
  13. differ_ <- 0.1
  14. # Algorithm to calculate walk phase
  15. f <- function(x) (sin((x - 5) / 2.7) / 30) + WALKBASE
  16. # Draw Optimum walk
  17. lines(WALKING, f(WALKING), col = "red", type = "l")
  18. # Check if each point is close to optimum track
  19. WALK <- data.frame(index=WALKING)
  20. WALK$probability <- 0
  21. for(i in WALKING){
  22. prob_ <- 1 - abs((abs(DATA[i,]$Head.y - f(i))) / differ_)
  23. #print(DATA[i,]$Head.y)
  24. #print(f(i))
  25. #print(prob_)
  26. #print("======")
  27. WALK[WALK$index==i,]$probability <- if(prob_ > 1) 1 else if(prob_ < 0) 0 else prob_
  28. }
  29. # points(WALK[WALK$probability == min(WALK$probability),]$index, 0.3)
  30. # points(WALK[WALK$probability == max(WALK$probability),]$index, 0.3)
  31. # Print out possible fall chance
  32. print(paste("FALL CHANCE BASED ON STEPS: ", as.character(specify_decimal(100-(mean(WALK$probability)*100), 2)), "%", sep = ""))
  33. print("DONE ANALYZING HEAD")
  34. # http://stats.stackexchange.com/questions/30975/how-to-add-non-linear-trend-line-to-a-scatter-plot-in-r
  35. # http://www.mathsisfun.com/geometry/parabola.html