|
@@ -1,3 +1,4 @@
|
|
|
|
|
+print("START ANALYZING HEAD")
|
|
|
#color <- rainbow(length(STATE))
|
|
#color <- rainbow(length(STATE))
|
|
|
color <- c("red", "blue", "blue", "green")
|
|
color <- c("red", "blue", "blue", "green")
|
|
|
|
|
|
|
@@ -12,27 +13,34 @@ for(i in 1:nrow(DATA)){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-#Check if patient is walking straight enough
|
|
|
|
|
-differ_ <- 0.4
|
|
|
|
|
|
|
+#Check if patient is walking fast enough
|
|
|
|
|
+differ_ <- 0.1
|
|
|
|
|
|
|
|
-start <- min(WALKING)
|
|
|
|
|
-stop <- max(WALKING)
|
|
|
|
|
|
|
+# Algorithm to calculate walk phase
|
|
|
|
|
+f <- function(x) (sin((x - 5) / 2.7) / 30) + WALKBASE
|
|
|
|
|
|
|
|
|
|
+# Draw Optimum walk
|
|
|
|
|
+lines(WALKING, f(WALKING), col = "red", type = "l")
|
|
|
|
|
|
|
|
-segments(start, WALKBASE, stop, col = "black")
|
|
|
|
|
|
|
+# Check if each point is close to optimum track
|
|
|
|
|
+WALK <- data.frame(index=WALKING)
|
|
|
|
|
+WALK$probability <- 0
|
|
|
|
|
|
|
|
-#base <- mean(c(DATA[start,]$Head.y, DATA[stop,]$Head.y))
|
|
|
|
|
-#size_ <- 5
|
|
|
|
|
-# for(i in seq(start, stop, size_)){
|
|
|
|
|
-#
|
|
|
|
|
-# step <- mean(DATA[i:(i+size_),]$Head.y) - base
|
|
|
|
|
-#
|
|
|
|
|
-# for(j in 0:(size_ -1)){
|
|
|
|
|
-# if(DATA[i+j,]$state != 1) next
|
|
|
|
|
-# points(i+j, DATA[i+j,]$Head.y - step, p = "*")
|
|
|
|
|
-# }
|
|
|
|
|
-#
|
|
|
|
|
-# }
|
|
|
|
|
|
|
+for(i in WALKING){
|
|
|
|
|
+ prob_ <- 1 - abs((abs(DATA[i,]$Head.y - f(i))) / differ_)
|
|
|
|
|
+ #print(DATA[i,]$Head.y)
|
|
|
|
|
+ #print(f(i))
|
|
|
|
|
+ #print(prob_)
|
|
|
|
|
+ #print("======")
|
|
|
|
|
+ WALK[WALK$index==i,]$probability <- if(prob_ > 1) 1 else if(prob_ < 0) 0 else prob_
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# points(WALK[WALK$probability == min(WALK$probability),]$index, 0.3)
|
|
|
|
|
+# points(WALK[WALK$probability == max(WALK$probability),]$index, 0.3)
|
|
|
|
|
+
|
|
|
|
|
+# Print out possible fall chance
|
|
|
|
|
+print(paste("FALL CHANCE BASED ON STEPS: ", as.character(specify_decimal(100-(mean(WALK$probability)*100), 2)), "%", sep = ""))
|
|
|
|
|
|
|
|
|
|
+print("DONE ANALYZING HEAD")
|
|
|
# http://stats.stackexchange.com/questions/30975/how-to-add-non-linear-trend-line-to-a-scatter-plot-in-r
|
|
# http://stats.stackexchange.com/questions/30975/how-to-add-non-linear-trend-line-to-a-scatter-plot-in-r
|
|
|
# http://www.mathsisfun.com/geometry/parabola.html
|
|
# http://www.mathsisfun.com/geometry/parabola.html
|