Created
December 19, 2014 22:59
-
-
Save Tafkas/e9f0e293dc7df9d36264 to your computer and use it in GitHub Desktop.
Fitbit Stride Length Linear Regression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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