-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.Rhistory
More file actions
170 lines (170 loc) · 7.79 KB
/
Copy path.Rhistory
File metadata and controls
170 lines (170 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
source('~/GitHub/Strava-Analysis-Using-R/Strava.r')
library(xlsx)
library(broom)
library(psych)
library("ggplot2")
data_types <- c('character', 'numeric', 'numeric', 'numeric', 'numeric', 'numeric', 'numeric', 'character',
'character', 'character', 'character', 'character', 'character', 'numeric', 'numeric', 'numeric',
'numeric', 'numeric', 'numeric')
strava_data <- read.xlsx("./all_data.xlsx", 1, colClasses = data_types, header=TRUE)
# Only ride data
ride_data <- subset(strava_data, type == 'VirtualRide' | type == 'Ride')
assumptions <- function(field_label, data, field, bins) {
gg <- ggplot(data, aes(field)) + geom_histogram(bins=bins) +
stat_function(fun=dnorm, args=list(mean = mean(field, na.rm=TRUE), sd = sd(field, na.rm=TRUE)),
color='black', size=1) +
ggtitle(field_label) + xlab(field_label) + ylab('Count')
gg <- ggplot(data, aes(field)) + geom_histogram()
print(gg)
qq <- qplot(sample=field)
print(qq)
d <- describe(field)
print(d)
kurtosis <- d$kurtosis
if (round(kurtosis, 2) > 0) {
print(paste('Kurtosis is', round(kurtosis, 2), '. Since it\'s greater than zero, there may be',
'a heavily-tailed distribution. Ideally, this should be zero.'))
} else if (round(kurtosis, 2) < 0) {
print(paste('Kurtosis is', round(kurtosis, 2), '. Since it\'s less than zero, there may be',
'a light-tailed distribution. Ideally, this should be zero.'))
} else {
print('The Kurtosis is 0, which indicates a normal distribution.')
}
skew <- d$skew
if (round(skew, 2) > 0) {
print(paste('Skew is', round(skew, 2), '. Since it\'s greater than zero, there may be ',
'a pile up of scores on the left of the distribution. Ideally, this should be zero.'))
} else if (round(skew, 2) < 0) {
print(paste('Skew is', round(skew, 2), '. Since it\'s less than zero, there may be ',
'a pile up of scores on the right of the distribution. Ideally, this should be zero.'))
} else {
print('The Skew is 0, which indicates a normal distribution.')
}
}
a <- assumptions('Average Speed (MPH)', ride_data, ride_data$average_speed_mph, 15)
View(ride_data)
a <- assumptions('Distance (Miles)', ride_data, ride_data$distance_mi, 15)
a <- assumptions('Moving Time (Minutes)', ride_data, ride_data$moving_time, 15)
a <- assumptions('Elevation Gain (Feet)', ride_data, ride_data$elevation_gain_ft, 15)
a <- assumptions('Average Power (Watts)', ride_data, ride_data$average_watts, 15)
a <- assumptions('Average Heart Rate', ride_data, ride_data$average_heartrate, 15)
a <- assumptions('Average Temperature (Celsius)', ride_data, ride_data$average_temp, 15)
ggplot(ride_data, aes(x = distance_mi, y = avg_speed_mph), color = factor(gear_id)) +
geom_point()
a <- assumptions('Average Speed (MPH)', ride_data, ride_data$average_speed_mph, 15)
ggplot(ride_data, aes(x = distance_mi, y = average_speed_mph), color = factor(gear_id)) +
geom_point()
cor(some_bikes$distance_mi, strava_data$average_speed_mph)
# try parallel slopes
# Augment the model
augmented_bikes <- augment(lm_speed_dist_gear_id)
# Simple lm model - how distance affects speed
lm_speed_dist_gear_id <- lm(average_speed_mph ~ distance_mi + factor(gear_id), data = ride_data)
summary(lm_speed_dist_gear_id)
lm_speed_dist_gear_id
a <- assumptions('Average Speed (MPH)', ride_data, ride_data$average_speed_mph, 15)
library(xlsx)
library(broom)
library(psych)
library("ggplot2")
library(xlsx)
library(broom)
library(psych)
library("ggplot2")
a <- assumptions('Average Speed (MPH)', ride_data, ride_data$average_speed_mph, 15)
View(strava_data)
View(ride_data)
print(typeof(ride_data$average_speed_mph))
View(ride_data)
View(ride_data)
print(typeof(ride_data$elevation_gain_ft))
describe(ride_data$average_speed_mph)
describe(ride_data$average_speed_mph)
View(ride_data)
strava_data <- read.xlsx("./all_data.xlsx", 1, colClasses = data_types, header=TRUE)
# Only ride data
ride_data <- subset(strava_data, type == 'VirtualRide' | type == 'Ride')
describe(ride_data$average_speed_mph)
print(typeof(ride_data$average_speed_mph))
View(ride_data)
# All data
data_types <- c('character', 'numeric', 'numeric', 'numeric', 'numeric', 'numeric', 'numeric', 'character',
'character', 'character', 'numeric', 'numeric', 'numeric', 'numeric', 'numeric', 'numeric')
strava_data <- read.xlsx("./all_data.xlsx", 1, colClasses = data_types, header=TRUE)
# Only ride data
ride_data <- subset(strava_data, type == 'VirtualRide' | type == 'Ride')
print(typeof(ride_data$average_speed_mph))
describe(ride_data$average_speed_mph)
assumptions <- function(field_label, data, field, bins) {
gg <- ggplot(data, aes(field)) + geom_histogram(bins=bins) +
stat_function(fun=dnorm, args=list(mean = mean(field, na.rm=TRUE), sd = sd(field, na.rm=TRUE)),
color='black', size=1) +
ggtitle(field_label) + xlab(field_label) + ylab('Count')
gg <- ggplot(data, aes(field)) + geom_histogram()
print(gg)
qq <- qplot(sample=field)
print(qq)
d <- describe(field)
print(d)
kurtosis <- d$kurtosis
if (round(kurtosis, 2) > 0) {
print(paste('Kurtosis is', round(kurtosis, 2), '. Since it\'s greater than zero, there may be',
'a heavily-tailed distribution. Ideally, this should be zero.'))
} else if (round(kurtosis, 2) < 0) {
print(paste('Kurtosis is', round(kurtosis, 2), '. Since it\'s less than zero, there may be',
'a light-tailed distribution. Ideally, this should be zero.'))
} else {
print('The Kurtosis is 0, which indicates a normal distribution.')
}
skew <- d$skew
if (round(skew, 2) > 0) {
print(paste('Skew is', round(skew, 2), '. Since it\'s greater than zero, there may be ',
'a pile up of scores on the left of the distribution. Ideally, this should be zero.'))
} else if (round(skew, 2) < 0) {
print(paste('Skew is', round(skew, 2), '. Since it\'s less than zero, there may be ',
'a pile up of scores on the right of the distribution. Ideally, this should be zero.'))
} else {
print('The Skew is 0, which indicates a normal distribution.')
}
}
a <- assumptions('Average Speed (MPH)', ride_data, ride_data$average_speed_mph, 15)
a <- assumptions('Distance (Miles)', ride_data, ride_data$distance_mi, 15)
a <- assumptions('Moving Time (Minutes)', ride_data, ride_data$moving_time, 15)
a <- assumptions('Elevation Gain (Feet)', ride_data, ride_data$elevation_gain_ft, 15)
a <- assumptions('Average Power (Watts)', ride_data, ride_data$average_watts, 15)
a <- assumptions('Average Heart Rate', ride_data, ride_data$average_heartrate, 15)
a <- assumptions('Average Temperature (Celsius)', ride_data, ride_data$average_temp, 15)
a <- assumptions('Average Heart Rate', ride_data, ride_data$average_heartrate, 15)
a <- assumptions('Average Temperature (Celsius)', ride_data, ride_data$average_temp, 15)
ggplot(ride_data, aes(x = distance_mi, y = average_speed_mph), color = factor(gear_id)) +
geom_point()
cor(some_bikes$distance_mi, strava_data$average_speed_mph)
View(ride_data)
View(ride_data)
# Only ride data
ride_data <- subset(strava_data, (type == 'VirtualRide' | type == 'Ride') & average_watts > 0)
View(ride_data)
ggplot(ride_data, aes(x = distance_mi, y = average_speed_mph), color = factor(gear_id)) +
geom_point()
cor(ride_data$distance_mi, strava_data$average_speed_mph)
# boxplot with just some bikes
ggplot(data = ride_data, aes(x = factor(gear_id), y = average_speed_mph)) +
geom_boxplot()
# Simple lm model - how distance affects speed
lm_speed_dist_gear_id <- lm(average_speed_mph ~ distance_mi + factor(gear_id), data = ride_data)
summary(lm_speed_dist_gear_id)
lm_speed_dist_gear_id
# try parallel slopes
# Augment the model
augmented_bikes <- augment(lm_speed_dist_gear_id)
# scatterplot, with color
lm_plot <- ggplot(augmented_bikes, aes(x = distance_mi, y = average_speed_mph, color = factor.gear_id.)) +
geom_point()
# single call to geom_line()
lm_plot + geom_line(aes(y = .fitted))
lm_plot.Show()
summary(logistic_model)
model_chi <- logistic_model.1$null.deviance - logistic_model.1$deviance
# scatterplot, with color
lm_plot <- ggplot(augmented_bikes, aes(x = distance_mi, y = average_speed_mph, color = factor.gear_id.)) +
geom_point()