-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths4-serve-speed-example-with-answers.R
37 lines (26 loc) · 1.31 KB
/
s4-serve-speed-example-with-answers.R
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
library(dplyr)
library(datavolley)
library(mgcv)
library(ggplot2)
# Serve agressiveness
sx <- readRDS("example_data/DE Men 2019/processed.rds")
dat <- sx %>% dplyr::filter(skill == "Serve") %>% mutate(bp = case_when(team == point_won_by ~ 1,
TRUE ~ 0),
err = evaluation == "Error") %>% group_by(match_id, set_number, team) %>%
summarise(bp_rate = mean(bp), err_rate = mean(err), n = n()) %>% ungroup()
ggplot(data = dat, aes(x = err_rate, y = bp_rate) )+ geom_point() + geom_smooth(method = 'gam', method.args = list(family = 'betar'))
# Serve speed
# Data kindly provided by Felipe Lima (Ori)
sx <- readRDS(file = "example_data/Serve_Speed_Example/serve_speed_example.rds")
dat <- dplyr::filter(sx, skill_type == "Jump serve" & serve_speed >= 60) %>%
mutate(player = as.factor(player_id),
err = evaluation == "Error",
pos = evaluation_code %in% c("+", "#", "/"),
neg = evaluation_code %in% c("=", "-"))
##fite <- gam(err ~ s(serve_speed) + s(player, bs = "re"), data = dat, family = binomial)
fiterr <- gam(err ~ s(serve_speed), data = dat, family = binomial)
fitpos <- gam(pos ~ s(serve_speed), data = dat, family = binomial)
fitneg <- gam(neg ~ s(serve_speed), data = dat, family = binomial)
plot(fiterr)
plot(fitpos)
plot(fitneg)