Skip to content

Commit

Permalink
fix: ID ordering differences *_aucs() / *_slopes()
Browse files Browse the repository at this point in the history
Fixes #127
  • Loading branch information
mcanouil committed Nov 11, 2024
1 parent 493b87c commit 68b91e1
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 229 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: eggla
Title: Early Growth Genetics Longitudinal Analysis
Version: 1.0.2
Version: 1.0.3
Authors@R:
c(person(given = "Mickaël",
family = "Canouil",
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# eggla 1.0.3

## Fixes

- In `R/*_aucs.R`, `R/*_slopes.R`,
- fix: sort rows by IDs ([#127](https://github.com/mcanouil/eggla/issues/127), thanks @DrGengWang).
- fix: ensure denominator's length depends on the number of knots. ([#127](https://github.com/mcanouil/eggla/issues/127), thanks @DrGengWang)

## Tests

- In `tests/testthat`,
- test: update snapshots

# eggla 1.0.2

## Fixes
Expand Down
3 changes: 2 additions & 1 deletion R/compute_aucs.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ compute_aucs <- function(
sapply(
X = x,
FUN = function(x) {
y_tmp <- coeff * c(x^0, x^1, x^2, x^3, (x - knots)^3) / c(1, 1, 2, rep(6, 4))
y_tmp <- coeff * c(x^0, x^1, x^2, x^3, (x - knots)^3) / c(1, 1, 2, rep(6, length(knots) + 1))
sum(y_tmp[seq_len(4 + findInterval(x, knots, left.open = TRUE))])
}
)
Expand All @@ -140,6 +140,7 @@ compute_aucs <- function(
)

out <- cbind.data.frame(Row.names = rownames(pred_auc), pred_auc)
out <- out[order(out[["Row.names"]]), ]
names(out)[grepl("Row.names", names(out), fixed = TRUE)] <- id_var
out
}
4 changes: 2 additions & 2 deletions R/compute_slopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ compute_slopes <- function(
coeff <- fxef + as.numeric(rnef[i, ]) # this implies fixed = random
for (j in seq_len(length(period) / 2)) {
x1 <- period[j * 2 - 1]
y1_tmp <- coeff * c(x1^0, x1^1, x1^2, x1^3, (x1 - knots)^3) / c(1, 1, 2, rep(6, 4))
y1_tmp <- coeff * c(x1^0, x1^1, x1^2, x1^3, (x1 - knots)^3) / c(1, 1, 2, rep(6, length(knots) + 1))
y1 <- sum(y1_tmp[seq_len(4 + findInterval(x1, knots, left.open = TRUE))])

x2 <- period[j * 2]
y2_tmp <- coeff * c(x2^0, x2^1, x2^2, x2^3, (x2 - knots)^3) / c(1, 1, 2, rep(6, 4))
y2_tmp <- coeff * c(x2^0, x2^1, x2^2, x2^3, (x2 - knots)^3) / c(1, 1, 2, rep(6, length(knots) + 1))
y2 <- sum(y2_tmp[seq_len(4 + findInterval(x2, knots, left.open = TRUE))])

pred[i, j * 2 - 1] <- y1
Expand Down
3 changes: 2 additions & 1 deletion R/egg_aucs.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ egg_aucs <- function(
sapply(
X = x,
FUN = function(x) {
y_tmp <- coeff * c(x^0, x^1, x^2, x^3, (x - knots)^3) / c(1, 1, 2, rep(6, 4))
y_tmp <- coeff * c(x^0, x^1, x^2, x^3, (x - knots)^3) / c(1, 1, 2, rep(6, length(knots) + 1))
sum(y_tmp[seq_len(4 + findInterval(x, knots, left.open = TRUE))])
}
)
Expand All @@ -93,6 +93,7 @@ egg_aucs <- function(
}

out <- cbind.data.frame(Row.names = rownames(pred_auc), pred_auc)
out <- out[order(out[["Row.names"]]), ]
names(out)[grepl("Row.names", names(out), fixed = TRUE)] <- id_var
out
}
4 changes: 2 additions & 2 deletions R/egg_slopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ egg_slopes <- function(
x1 <- period[j * 2 - 1]
y1_tmp <- coeff *
c(x1^0, x1^1, x1^2, x1^3, (x1 - knots)^3) /
c(1, 1, 2, rep(6, 4))
c(1, 1, 2, rep(6, length(knots) + 1))
y1 <- sum(y1_tmp[seq_len(4 + findInterval(x1, knots, left.open = TRUE))])

x2 <- period[j * 2]
y2_tmp <- coeff *
c(x2^0, x2^1, x2^2, x2^3, (x2 - knots)^3) /
c(1, 1, 2, rep(6, 4))
c(1, 1, 2, rep(6, length(knots) + 1))
y2 <- sum(y2_tmp[seq_len(4 + findInterval(x2, knots, left.open = TRUE))])

pred[i, j * 2 - 1] <- y1
Expand Down
78 changes: 39 additions & 39 deletions tests/testthat/_snaps/egg_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,56 @@
out
Output
ID auc_0--0.5 auc_1.5--3.5 auc_6.5--10 auc_12--17
082 082 1.38 5.76 11.30 18.04
083 083 1.37 5.61 10.62 16.39
080 080 1.38 5.77 11.47 18.51
031 031 1.38 5.71 11.04 17.37
007 007 1.38 5.84 11.79 19.28
033 033 1.41 5.87 11.60 18.63
076 076 1.39 5.80 11.48 18.45
063 063 1.38 5.74 11.25 17.93
001 001 1.41 5.85 11.46 18.26
004 004 1.37 5.72 11.22 17.89
054 054 1.39 5.73 10.97 17.12
089 089 1.37 5.69 11.11 17.64
095 095 1.37 5.74 11.33 18.19
093 093 1.39 5.87 11.89 19.47
088 088 1.39 5.76 11.19 17.68
022 022 1.39 5.79 11.38 18.17
005 005 1.38 5.77 11.39 18.28
006 006 1.36 5.62 10.83 17.01
019 019 1.38 5.76 11.37 18.23
044 044 1.42 5.92 11.69 18.75
007 007 1.38 5.84 11.79 19.28
009 009 1.38 5.71 11.11 17.59
010 010 1.38 5.79 11.54 18.67
011 011 1.38 5.75 11.24 17.88
012 012 1.41 5.81 11.21 17.63
013 013 1.39 5.82 11.60 18.74
016 016 1.38 5.70 11.07 17.51
019 019 1.38 5.76 11.37 18.23
022 022 1.39 5.79 11.38 18.17
025 025 1.38 5.71 11.01 17.30
061 061 1.38 5.68 10.95 17.21
048 048 1.38 5.73 11.10 17.51
031 031 1.38 5.71 11.04 17.37
032 032 1.38 5.68 10.94 17.15
033 033 1.41 5.87 11.60 18.63
034 034 1.39 5.78 11.42 18.33
035 035 1.38 5.77 11.40 18.29
039 039 1.40 5.71 10.75 16.52
041 041 1.38 5.74 11.17 17.69
044 044 1.42 5.92 11.69 18.75
045 045 1.38 5.70 10.96 17.16
086 086 1.38 5.70 11.02 17.35
092 092 1.39 5.75 11.14 17.56
085 085 1.36 5.63 10.83 16.99
059 059 1.38 5.74 11.21 17.83
046 046 1.39 5.74 11.13 17.59
069 069 1.37 5.68 10.99 17.33
081 081 1.37 5.58 10.45 15.99
048 048 1.38 5.73 11.10 17.51
049 049 1.39 5.80 11.49 18.47
072 072 1.39 5.76 11.14 17.55
099 099 1.39 5.80 11.52 18.56
064 064 1.36 5.66 11.16 17.88
009 009 1.38 5.71 11.11 17.59
032 032 1.38 5.68 10.94 17.15
011 011 1.38 5.75 11.24 17.88
075 075 1.37 5.67 11.03 17.46
054 054 1.39 5.73 10.97 17.12
057 057 1.38 5.70 11.01 17.32
012 012 1.41 5.81 11.21 17.63
059 059 1.38 5.74 11.21 17.83
061 061 1.38 5.68 10.95 17.21
063 063 1.38 5.74 11.25 17.93
064 064 1.36 5.66 11.16 17.88
065 065 1.36 5.70 11.29 18.16
041 041 1.38 5.74 11.17 17.69
035 035 1.38 5.77 11.40 18.29
016 016 1.38 5.70 11.07 17.51
010 010 1.38 5.79 11.54 18.67
034 034 1.39 5.78 11.42 18.33
001 001 1.41 5.85 11.46 18.26
005 005 1.38 5.77 11.39 18.28
068 068 1.39 5.77 11.33 18.09
069 069 1.37 5.68 10.99 17.33
072 072 1.39 5.76 11.14 17.55
075 075 1.37 5.67 11.03 17.46
076 076 1.39 5.80 11.48 18.45
080 080 1.38 5.77 11.47 18.51
081 081 1.37 5.58 10.45 15.99
082 082 1.38 5.76 11.30 18.04
083 083 1.37 5.61 10.62 16.39
085 085 1.36 5.63 10.83 16.99
086 086 1.38 5.70 11.02 17.35
088 088 1.39 5.76 11.19 17.68
089 089 1.37 5.69 11.11 17.64
092 092 1.39 5.75 11.14 17.56
093 093 1.39 5.87 11.89 19.47
095 095 1.37 5.74 11.33 18.19
099 099 1.39 5.80 11.52 18.56

---

Expand Down
Loading

0 comments on commit 68b91e1

Please sign in to comment.