Skip to content

Commit 279c659

Browse files
committed
fix mathjax
update rounding strategy
1 parent 16cde0d commit 279c659

8 files changed

Lines changed: 34 additions & 18 deletions

File tree

R/LEAV.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#'
2020
#' For accessions in a collection compute the Length of Encoded Attribute Values
2121
#' (LEAV) information measure from qualitative and quantitative trait data
22-
#' \insertCite{wallace_information_1968,balakrishnan_Strategies_2001,balakrishnan_Strategies_2001a,balakrishnan_Strategies_2003}{LEAVcore}
23-
#' \loadmathjax.
22+
#' \insertCite{wallace_information_1968,balakrishnan_Strategies_2001,balakrishnan_Strategies_2001a,balakrishnan_Strategies_2003}{LEAVcore}.
23+
#' \loadmathjax
2424
#'
2525
#' For each accession \mjseqn{s} in the collection, the message length
2626
#' \mjseqn{F_{s}} to optimally encode all the \mjseqn{d} traits/descriptors is
@@ -101,7 +101,7 @@
101101
#' freq_list <- lapply(qual, function(x) {
102102
#' prop <- prop.adj(cassava_EC[, x], method = "sqrt")
103103
#' size.count <- ceiling(size * length(x))
104-
#' round.to.target(prop * size.count)
104+
#' round_to_target(prop * size.count)
105105
#' })
106106
#' names(freq_list) <- qual
107107
#'

R/LEAVcore.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LEAVcore <- function(data, names,
3131
fqout <- prop * size.count
3232
fq_overall <- summary(data[, x])
3333
fqout <- ifelse(fqout > fq_overall, fq_overall, fqout)
34-
fqout <- round.to.target(fqout)
34+
fqout <- round_to_target(fqout)
3535
return(fqout)
3636
})
3737
names(freq1) <- qualitative
@@ -99,7 +99,7 @@ LEAVcore <- function(data, names,
9999
freq <- lapply(qualitative, function(x) {
100100
prop <- prop.adj(data[, x], method = prop.adj)
101101
fqout <- prop * nrow(data)
102-
# fqout <- round.to.target(fqout)
102+
# fqout <- round_to_target(fqout)
103103
return(fqout)
104104
})
105105
names(freq) <- qualitative
@@ -117,7 +117,8 @@ LEAVcore <- function(data, names,
117117

118118
## Estimate LEAV ----
119119
LEAVdf <- LEAV(data = data, names = names,
120-
quantitative = quantitative, qualitative = qualitative,
120+
quantitative = quantitative,
121+
qualitative = qualitative,
121122
adj = FALSE,
122123
freq = freq, mean = mean, sd = sd, e = e)
123124

@@ -139,7 +140,7 @@ LEAVcore <- function(data, names,
139140

140141
}
141142

142-
round.to.target <- function(x, target = round(sum(x))) {
143+
round_to_target <- function(x, target = round(sum(x))) {
143144

144145
while(sum(round(x)) - target > 0) {
145146
i <- which.min(ifelse(x %% 1 < 0.5, 1, x %% 1))
@@ -151,3 +152,17 @@ round.to.target <- function(x, target = round(sum(x))) {
151152
}
152153
round(x)
153154
}
155+
156+
# Hamilton rounding
157+
# largest remainder method
158+
round_preserve_sum <- function(x, target = round(sum(x))) {
159+
y <- floor(x)
160+
deficit <- target - sum(y)
161+
162+
if(deficit > 0) {
163+
idx <- order(x - y, decreasing = TRUE)[1:deficit]
164+
y[idx] <- y[idx] + 1
165+
}
166+
167+
y
168+
}

R/inflen.qual.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#'
2020
#' The function \code{inflen.qual} computes the length of information code that
2121
#' can indicate the possession of a descriptor state of a qualitative trait
22-
#' \insertCite{wallace_information_1968,balakrishnan_Strategies_2001,balakrishnan_Strategies_2001a,balakrishnan_Strategies_2003}{LEAVcore}
23-
#' \loadmathjax.
22+
#' \insertCite{wallace_information_1968,balakrishnan_Strategies_2001,balakrishnan_Strategies_2001a,balakrishnan_Strategies_2003}{LEAVcore}.
23+
#' \loadmathjax
2424
#'
2525
#' For each qualitative trait/descriptor \mjseqn{d} the probability of
2626
#' occurrence of a descriptor state \mjseqn{m} in the in a subset \mjseqn{t} is

R/inflen.quant.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#'
2020
#' The function \code{inflen.quant} computes the length of information code that
2121
#' can indicate the possession of a specific value by a quantitative trait
22-
#' \insertCite{wallace_information_1968,balakrishnan_Strategies_2001,balakrishnan_Strategies_2001a,balakrishnan_Strategies_2003}{LEAVcore}
23-
#' \loadmathjax.
22+
#' \insertCite{wallace_information_1968,balakrishnan_Strategies_2001,balakrishnan_Strategies_2001a,balakrishnan_Strategies_2003}{LEAVcore}.
23+
#' \loadmathjax
2424
#'
2525
#' For each quantitative trait \mjseqn{d}, it is assumed that it is normally
2626
#' distributed within subset \mjseqn{t} with mean \mjseqn{\mu_{d,t}} and the

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
template:
22
bootstrap: 5
33
light-switch: yes
4+
math-rendering: mathjax
45
bslib:
56
base_font:
67
google: Fira Sans

man/LEAV.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/inflen.qual.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/inflen.quant.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)