author: BEAP Lab date: May 9-10, 2019 autosize: true
<iframe src="https://giphy.com/embed/1uyFaGpt2ilmE" width="576" height="576" frameBorder="0" class="giphy-embed" allowFullScreen></iframe> <iframe src="https://giphy.com/embed/7PfwoiCwBp6Ra" width="576" height="460" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>- Name
- Why you chose this course
- Experience with computer code
- All phones have them (new phones have 2-3)
- Measure physical activity, sleep, and sedentary behaviour
- Provide lots of cool data
- Easy to configure and download data
- Lots of user control
- Fixed position on the body
- Global Positioning System
- Only works on PC
- We have setup most of the devices
- Will walk through setup of one device
- Plug in your SenseDoc
- Export the data to desktop
- Name it something reasonable
- Check the file
- How might you do that?
The R project for statistical computing is a free open source statistical programming language and project.
<iframe src="https://player.vimeo.com/video/97166163?color=428bca&title=0&byline=0&portrait=0" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>- 2 types of coding
- Base R
- Tidyverse
- We will be using Tidyverse
- Lots of online tutorials
- Name things
- Use a case convention
- We will use
snake_case
- We will use
- Use tidy data principles
- Peer programming
- Pick a driver for now
- Pick who's data you will use
You can use R as a basic calculator. If you pass the command 2+2 it will return 4.
2+2
[1] 4
You can use arithmetic and mathematical operators in your commands
Code | Action |
---|
- | Addition
- | Subtraction * | Multiplication / | Division ^ | Raise to the power of
2^4
[1] 16
Packages let you do things. If you have thought about doing it, there is a package already. There are two basic steps to using a package:
- Installing the package
install.packages("tidyverse")
- Loading the package
library(tidyverse)
accel_data <- read_csv("/Users/dfuller/Desktop/accel_data.csv")
Code | Description |
---|---|
accel_data |
Name of the object to save to memory |
<- |
Left assignment operator. Use it to store an object |
read_csv |
A function that does something |
("/Users/dfuller/Desktop/accel_data.csv") |
The object or location of the object the function should be applied to |
Mac
accel_data <- read_csv("/Users/dfuller/Desktop/accel_data.csv")
PC
accel_data <- read_csv("C:\\Users\\Andrie\\Desktop\\accel_data.csv")
- rowid: unique identifier for each row
- utcdate: the data to the second in utc time
- ts: second of measurement to 13 decimal places
- x: the x axis of acceleration measured in g units of gravity (1g = 9.81m/s^2)
- y: the x axis of acceleration measured in g
- z: the x axis of acceleration measured in g
head(accel_data)
mean(data$xcounts)
accel_mean_x <- accel_data %>%
summarize(
x_mean = mean(x),
x_sd = sd(x)
)
head(accel_mean_x)
accel_mean <- accel_data %>%
summarize(
x_mean = mean(x),
y_mean = mean(y),
z_mean = mean(z),
x_sd = sd(x),
y_sd = sd(y),
z_sd = sd(z),
)
head(accel_mean)
accel_hist_x <- ggplot(accel_data) +
geom_histogram(aes(x))
plot(accel_hist_x)
accel_dens_x <- ggplot(accel_data) +
geom_density(aes(x), colour = "blue")
plot(accel_dens_x)
accel_hist <- ggplot(accel_data) +
geom_density(aes(x), colour = "blue") +
geom_density(aes(y), colour = "red") +
geom_density(aes(z), colour = "purple")
plot(accel_hist)
accel_plot_x <- ggplot(accel_data) +
geom_point(aes(x = utcdate, y = x), colour = "blue", alpha = 0.1)
plot(accel_plot_x)
accel_plot <- ggplot(accel_data) +
geom_point(aes(x = utcdate, y = x), colour = "blue", alpha = 0.1) +
geom_point(aes(x = utcdate, y = y), colour = "red", alpha = 0.1) +
geom_point(aes(x = utcdate, y = z), colour = "green", alpha = 0.1)
plot(accel_plot)
- Walk to the Clock Tower
- Walk through the UC
- Walk around the duck pond
- Walk to the Tim's in the Aquarena
- Come back
- Plug in your SenseDoc
- Export the data to desktop
- Name it something reasonable
- Check the file
- How might you do that?
- Peer programming
- Pick a driver for now
- Pick who's data you will use
gps_data <- read_csv("/Users/dfuller/Desktop/gps_data.csv")
??????
gps_plot_1 <- ggplot(gps_data) +
geom_point(aes(x = lon, y = lat))
plot(gps_plot_1)
Need a Google Maps API Key
avalon_basemap <- get_map(location = "St. John's, Newfoundland, Canada",
source = "google",
maptype = "roadmap",
crop = FALSE,
zoom = 14)
plot(avalon_basemap)
maps_points <- ggmap(avalon_basemap) +
geom_point(aes(x = lon, y = lat), data = gps_data, alpha = 0.2)
plot(maps_points)
maps_points <- ggmap(avalon_basemap) +
geom_point(aes(x = lon, y = lat, colour = speed), data = gps_data, alpha = 0.2)
plot(maps_points)