Skip to content

Commit

Permalink
Extracted function to calculate y (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Jan 24, 2025
1 parent 2c20798 commit a40a76c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ person <- setRefClass(
bmi = "numeric"
)
)

y <- function(x, beta_hat, weights, grid) {
x <- matrix(rep(x, 4), ncol = 4L)
x <- as.matrix(cbind(t(x), grid, 1))
weights %*% exp(x %*% beta_hat)
}
6 changes: 2 additions & 4 deletions src/groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ simple <- group(
breathing_frequency = numeric()
),
vo2_ml_min = function(.self, person) {
x = c(person$height, log(person$bmi), person$height * person$sex)
x = matrix(rep(x, 4), ncol = 4L)
x = as.matrix(cbind(t(x), .self$grid, 1))
.self$haukeland_vyntus %*% exp(x %*% .self$beta_hat$vo2_ml_min)
x <- c(person$height, log(person$bmi), person$height * person$sex)
y(x, .self$beta_hat$vo2_ml_min, .self$haukeland_vyntus, .self$grid)
},
vo2_ml_kg_min = function(.self, person) {
results = apply(.self$grid, 1, function(config) {
Expand Down
1 change: 1 addition & 0 deletions src/server.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source("classes.R")
source("groups.R")


server <- function(input, output) {
output$results_table <- renderTable({
group <- get(input$group)
Expand Down

0 comments on commit a40a76c

Please sign in to comment.