Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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