Skip to content

Commit

Permalink
Merge pull request #29 from mladenjovanovic/in-situ-new-model-def
Browse files Browse the repository at this point in the history
In situ new model def
  • Loading branch information
mladenjovanovic committed Jan 18, 2024
2 parents 04f2b75 + a9a1301 commit b4778c3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
9 changes: 4 additions & 5 deletions DESCRIPTION
Expand Up @@ -9,11 +9,10 @@ Authors@R:
comment = c(ORCID = "0000-0002-4013-6530"))
)
Version: 3.0.0
Description: Create short sprint (<6sec) profiles using the split times or the radar gun data.
Mono-exponential equation is used to estimate maximal sprinting speed (MSS), relative acceleration (TAU),
and other parameters such us maximal acceleration (MAC) and maximal relative power (PMAX). These parameters
can be used to predict kinematic and kinetics variables and to compare individuals. The modeling method utilized
in this package is based on the works of
Description: Create short sprint acceleration-velocity (AVP) and force-velocity (FVP) profiles
and predict kinematic and kinetic variables using the timing-gate split times, laser or
radar gun data, tether devices data, as well as the data provided by the GPS and LPS
monitoring systems. The modeling method utilized in this package is based on the works of
Furusawa K, Hill AV, Parkinson JL (1927) <doi: 10.1098/rspb.1927.0035>,
Greene PR. (1986) <doi: 10.1016/0025-5564(86)90063-5>,
Chelly SM, Denis C. (2001) <doi: 10.1097/00005768-200102000-00024>,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
@@ -1,3 +1,9 @@
# shorts 3.1.0

* Fixed the error in `model_radar_gun()` example that happened on `r-release-macos-arm64` and `r-oldrel-macos-arm64` due to the perfect model fit causing "singular gradient matrix at initial parameter estimates". This is sorted by adding simple noise to the simulated data
* Modified `model_in_situ()` function to now use `minpack.lm::nlsLM()` instead of `stats::lm()` function, which now estimates `MSS` and `MAC` parameters, and it is thus easier to read the code, and estimate the confidence intervals
* Updated the DESCRIPTION file with better package description

# shorts 3.0.0

## Fixed Bugs and Errors
Expand Down
30 changes: 19 additions & 11 deletions R/model-in-situ.R
Expand Up @@ -53,7 +53,10 @@ prepare_in_situ_data <- function(df,
#'
#' # Model In-Situ (Embedded profiling)
#' data("LPS_session")
#' m1 <- model_in_situ(LPS_session$velocity, LPS_session$acceleration)
#' m1 <- model_in_situ(
#' velocity = LPS_session$velocity,
#' acceleration = LPS_session$acceleration,
#' velocity_threshold = 4)
#' m1
#' plot(m1)
#'
Expand Down Expand Up @@ -87,21 +90,26 @@ model_in_situ <- function(velocity,
na.rm = na.rm
)

param_start <- list(MSS = 7, MAC = 7)
param_lower <- c(MSS = 0, MAC = 0)
param_upper <- c(MSS = Inf, MAC = Inf)

# Linear model
model <- stats::lm(
acceleration ~ velocity,
model <- minpack.lm::nlsLM(
acceleration ~ predict_acceleration_at_velocity(velocity, MSS, MAC),
data = train,
weights = train$weight
start = param_start,
lower = param_lower,
upper = param_upper,
weights = train$weight,
...
)

# Get parameters
slope <- stats::coef(model)[[2]]
MAC <- stats::coef(model)[[1]]

MSS <- -MAC / slope
# Parameters
MSS <- stats::coef(model)[["MSS"]]
MAC <- stats::coef(model)[["MAC"]]
TAU <- MSS / MAC

PMAX <- MSS * MAC / 4
PMAX <- (MSS * MAC) / 4

# Model fit
pred_acceleration <- stats::predict(model, newdata = data.frame(velocity = test$velocity))
Expand Down
4 changes: 4 additions & 0 deletions R/model-radar-gun.R
Expand Up @@ -6,6 +6,10 @@
#'
#' # Model Radar Gun (includes Time Correction)
#' df <- create_sprint_trace(MSS = 8, MAC = 6, time = seq(0, 6, 0.1))
#'
#' # Add some noise
#' df$velocity <- df$velocity + rnorm(n = nrow(df), 0, 10^-2)
#'
#' m1 <- model_radar_gun(time = df$time, velocity = df$velocity)
#' m1
#' plot(m1)
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Expand Up @@ -8,7 +8,7 @@ bibentry(
email = "coach.mladen.jovanovic@gmail.com")
),
year = "2024",
note = "R package version 3.0.0",
note = "R package version 3.1.0",
url = "https://CRAN.R-project.org/package=shorts",
key = "shorts-package"
)
9 changes: 8 additions & 1 deletion man/model_functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b4778c3

Please sign in to comment.