Skip to content

Commit 03de0f8

Browse files
exposed rounding option
1 parent c337a29 commit 03de0f8

5 files changed

Lines changed: 24 additions & 10 deletions

File tree

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ACEsimFit (development version)
22
* Added a `NEWS.md` file to track changes to the package.
3-
3+
* Exposed rounding parameter in `sim_kin_pairs()` function.
44

55
# ACEsimFit (0.0.0.9)
66
* Uploaded to CRAN on 2022-10-10 22:03:05 UTC

R/Power_LS.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Power_LS
22
#' @description The function is designed for calculating the power of heritability estimation from ACE models given the parameter settings. Or calculate one of the parameter settings (N,R,h2,c2) given the rest of known parameters.
3-
#' This power calculator is made based on the Least Squares theory and follows the mathematical derivation proposed by Visscher(2004).
3+
#' This power calculator is made based on the Least Squares theory and follows the mathematical derivation proposed by Visscher (2004).
44
#' @import stats
55
#' @param N1 The number of kin pairs for group1 (amount of PAIRS)
66
#' @param N2 The number of kin pairs for group2
@@ -11,13 +11,14 @@
1111
#' @param R1 The genetic relatedness of kin pair group1
1212
#' @param R2 The genetic relatedness of kin pair group2
1313
#' @param alpha The type-one error rate for heritability estimation.
14+
#' @param digits The number of digits to round the results. Default is 0.
1415
#' @return A numeric \code{vector} of power when `N1` and `N2` are both specified.
1516
#' \cr
1617
#' A numeric \code{vector} of `N1` (or `N2`) when `N2` (or `N1`) is specified. A numeric \code{vector} of `N1` and `N2` when `RatioN` is specified.
1718
#' @export
1819

1920

20-
Power_LS <- function(N1, N2, power, p_N1 = NULL, h2, c2, R1 = 1, R2 = .5, alpha = .05) {
21+
Power_LS <- function(N1, N2, power, p_N1 = NULL, h2, c2, R1 = 1, R2 = .5, alpha = .05, digits = 0) {
2122
Za <- qnorm(1 - alpha)
2223

2324
if (missing(power)) {
@@ -28,18 +29,18 @@ Power_LS <- function(N1, N2, power, p_N1 = NULL, h2, c2, R1 = 1, R2 = .5, alpha
2829
if (!missing(N1) & missing(N2)) {
2930
Zb <- qnorm(power)
3031
N2_result <- (1 - (R2 * h2 + c2)^2)^2 / (h2^2 * (abs(R1 - R2)^2) / ((Za + Zb)^2) - ((1 - (R1 * h2 + c2)^2)^2 / N1))
31-
return(round(N2_result))
32+
return(round(N2_result, digits = digits))
3233
}
3334
if (missing(N1) & !missing(N2)) {
3435
Zb <- qnorm(power)
3536
N1_result <- (1 - (R1 * h2 + c2)^2)^2 / (h2^2 * (abs(R1 - R2)^2) / ((Za + Zb)^2) - ((1 - (R2 * h2 + c2)^2)^2 / N2))
36-
return(round(N1_result))
37+
return(round(N1_result, digits = digits))
3738
}
3839
if (missing(N1) & missing(N2) & !is.null(p_N1)) {
3940
Zb <- qnorm(power)
4041
N_total <- (1 - (R1 * h2 + c2)^2)^2 / (p_N1 * h2^2 * abs(R1 - R2)^2 / ((Za + Zb)^2)) + (1 - (R2 * h2 + c2)^2)^2 / ((1 - p_N1) * h2^2 * (abs(R1 - R2)^2) / ((Za + Zb)^2))
4142
N1_result <- N_total * p_N1
4243
N2_result <- N_total * (1 - p_N1)
43-
return(c(round(N1_result), round(N2_result)))
44+
return(c(round(N1_result, digits = digits), round(N2_result, digits = digits)))
4445
}
4546
}

R/kinsim_single.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#' @description The function to generate one group of univariate kin pair (e.g., only DZ twins) data using a multivariate norm approach, given the ACE components.
33
#' @param name Assigned name for the simulated group of kin pairs
44
#' @param Rel Genetic relatedness of the simulated kin pairs
5-
#' @param r_c Assumed common enviroment correlation
5+
#' @param r_c Assumed common environment correlation
66
#' @param n The number of generated kin pairs.(n PAIRS of data; The total number of participants is 2n)
77
#' @param mu The mean for generated variable
88
#' @param ace Vector of variance components under an ACE (additive genetics, common environment, unique environment) structure

man/Power_LS.Rd

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

man/kinsim_single.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)