Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Created December 19, 2014 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tafkas/e9f0e293dc7df9d36264 to your computer and use it in GitHub Desktop.
Save Tafkas/e9f0e293dc7df9d36264 to your computer and use it in GitHub Desktop.
Fitbit Stride Length Linear Regression
runs <- read.csv("myrunninglog.csv", header=T, sep=",")
#convert date
runs$Date <- strptime(as.character(runs$Date), format="%Y-%m-%d")
#convert distance from km to meters
runs$Distance <- 1000 * runs$Distance
ggplotRegression <- function (fit) {
require(ggplot2)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) +
geom_point() +
stat_smooth(method = "lm", col = "red") +
ggtitle(paste("Adj R2 = ",signif(summary(fit)$adj.r.squared, 5),
"; Intercept =",signif(fit$coef[[1]],5 ),
"; Slope =",signif(fit$coef[[2]], 5),
"; P =",signif(summary(fit)$coef[2,4], 5)))
}
ggplotRegression(lm(Distance ~ Steps, data = runs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment