Skip to content
Merged

Dev #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Vectorizing `discord_data()` to improve performance.
* Adding tests to ensure comparability between optimized and non-optimized versions of `discord_data()`.
* Adding `discord_between_model()` to get the between-family model
* Added unique filter for `discord_data()` to ensure that the data is not duplicated.
* Added tests for categorical variables in `discord_data()`.

# discord 1.2.3.1
* More mild improvements to documentation
Expand Down
8 changes: 4 additions & 4 deletions R/func_discord_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ discord_data <- function(data,
fast = TRUE,
...) {
if (fast) {
discord_data_fast(
unique(discord_data_fast(
data = data,
outcome = outcome,
id = id,
Expand All @@ -58,9 +58,9 @@ discord_data <- function(data,
predictors = predictors,
coding_method = coding_method,
...
)
))
} else {
discord_data_ram_optimized(
unique(discord_data_ram_optimized(
data = data,
outcome = outcome,
id = id,
Expand All @@ -71,7 +71,7 @@ discord_data <- function(data,
predictors = predictors,
coding_method = coding_method,
...
)
))
}
}

Expand Down
6 changes: 5 additions & 1 deletion R/func_discord_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
data_processed = FALSE,
coding_method = "none",
fast = TRUE) {
if( data_processed == TRUE & !is.data.frame(data) ) {
stop("data must be a data frame if data_processed is TRUE")

Check warning on line 32 in R/func_discord_regression.R

View check run for this annotation

Codecov / codecov/patch

R/func_discord_regression.R#L32

Added line #L32 was not covered by tests
}
if( data_processed == FALSE){
check_discord_errors(data = data, id = id, sex = sex, race = race, pair_identifiers = pair_identifiers)

}
# if no demographics provided
if (is.null(demographics)) {
if (is.null(sex) & is.null(race)) {
Expand Down
12 changes: 6 additions & 6 deletions R/func_kinsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ kinsim <- function(
sigma_a[4, 1] <- cov_a * r_all[i]
sigma_a[3, 2] <- cov_a * r_all[i]
sigma_a[2, 3] <- cov_a * r_all[i]
A.r <- rmvn(n,
A.r <- .rmvn(n,
sigma = sigma_a
)

Expand All @@ -154,7 +154,7 @@ kinsim <- function(
sigma_c[4, 1] <- cov_c * 1
sigma_c[3, 2] <- cov_c * 1
sigma_c[2, 3] <- cov_c * 1
C.r <- rmvn(n,
C.r <- .rmvn(n,
sigma = sigma_c
)
C.r[, 1:2] <- C.r[, 1:2] * sC[1]
Expand All @@ -166,7 +166,7 @@ kinsim <- function(
sigma_e[3, 1] <- cov_e
sigma_e[2, 4] <- cov_e
sigma_e[4, 2] <- cov_e
E.r <- rmvn(n,
E.r <- .rmvn(n,
sigma = sigma_e
)
E.r[, 1:2] <- E.r[, 1:2] * sE[1]
Expand Down Expand Up @@ -225,7 +225,7 @@ kinsim <- function(
sigma_a[3, 2] <- cov_a * r_val
sigma_a[2, 3] <- cov_a * r_val

A_tmp <- rmvn(n_sub, sigma = sigma_a)
A_tmp <- .rmvn(n_sub, sigma = sigma_a)

A.r[idx, 1:2] <- A_tmp[, 1:2] * sA[1]
A.r[idx, 3:4] <- A_tmp[, 3:4] * sA[2]
Expand All @@ -241,7 +241,7 @@ kinsim <- function(
sigma_c[3, 2] <- cov_c * 1
sigma_c[2, 3] <- cov_c * 1

C_tmp <- rmvn(n_sub, sigma = sigma_c)
C_tmp <- .rmvn(n_sub, sigma = sigma_c)
C.r[idx, 1:2] <- C_tmp[, 1:2] * sC[1]
C.r[idx, 3:4] <- C_tmp[, 3:4] * sC[2]

Expand All @@ -252,7 +252,7 @@ kinsim <- function(
sigma_e[2, 4] <- cov_e
sigma_e[4, 2] <- cov_e

E_tmp <- rmvn(n_sub, sigma = sigma_e)
E_tmp <- .rmvn(n_sub, sigma = sigma_e)
E.r[idx, 1:2] <- E_tmp[, 1:2] * sE[1]
E.r[idx, 3:4] <- E_tmp[, 3:4] * sE[2]
}
Expand Down
13 changes: 7 additions & 6 deletions R/helpers_simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @return Matrix of dimension \code{n × ncol(sigma)} containing random samples
#' from the multivariate normal distribution.
#' @keywords internal
rmvn <- function(n, sigma) {
.rmvn <- function(n, sigma) {
Sh <- with(
svd(sigma),
v %*% diag(sqrt(d)) %*% t(u)
Expand Down Expand Up @@ -89,16 +89,17 @@ kinsim_internal <- function(


# Generate data for each relatedness group
for (i in 1:length(r)) {
# for (i in 1:length(r)) {
for (i in seq_along(r)) {
n <- npergroup[i]

# Generate correlated genetic components based on relatedness
A.r <- sA * rmvn(n, sigma = diag(2) + S2 * r[i])
A.r <- sA * .rmvn(n, sigma = diag(2) + S2 * r[i])

# Generate shared environmental components (same for both members)
# C.r <- stats::rnorm(n,sd = sC)
# C.r <- cbind(C.r,C.r )
C.r <- sC * rmvn(n, sigma = diag(2) + S2 * c_rel)
C.r <- sC * .rmvn(n, sigma = diag(2) + S2 * c_rel)

# Generate non-shared environmental components (different for each member)
E.r <- cbind(
Expand Down Expand Up @@ -140,7 +141,7 @@ kinsim_internal <- function(
# Generate genetic components for each unique relatedness value
for (i in 1:length(unique_r)) {
n <- length(r_vector[r_vector == unique_r[i]])
A.rz <- sA * rmvn(n, sigma = diag(2) + S2 * unique_r[i])
A.rz <- sA * .rmvn(n, sigma = diag(2) + S2 * unique_r[i])
data_vector$A.r1[data_vector$r_vector == unique_r[i]] <- A.rz[, 1]
data_vector$A.r2[data_vector$r_vector == unique_r[i]] <- A.rz[, 2]
}
Expand All @@ -149,7 +150,7 @@ kinsim_internal <- function(
data_vector$A.r1,
data_vector$A.r2
), ncol = 2)
C.r <- sC * rmvn(n, sigma = diag(2) + S2 * c_rel)
C.r <- sC * .rmvn(n, sigma = diag(2) + S2 * c_rel)

E.r <- cbind(
stats::rnorm(n, sd = sE),
Expand Down
3 changes: 3 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ knitr::opts_chunk$set(
[![R package version](https://www.r-pkg.org/badges/version/discord)](https://cran.r-project.org/package=discord)
[![Package downloads](https://cranlogs.r-pkg.org/badges/grand-total/discord)](https://cran.r-project.org/package=discord)</br>
[![R-CMD-check](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-check.yaml)
[![Dev Main branch](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-dev_check.yaml/badge.svg)](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-dev_check.yaml)
[![Codecov test coverage](https://codecov.io/gh/R-Computing-Lab/discord/graph/badge.svg)](https://app.codecov.io/gh/R-Computing-Lab/discord)
![License](https://img.shields.io/badge/License-GPL_v3-blue.svg)

<!-- badges: end -->

The goal of discord is to provide functions for discordant kinship
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ version](https://www.r-pkg.org/badges/version/discord)](https://cran.r-project.o
[![Package
downloads](https://cranlogs.r-pkg.org/badges/grand-total/discord)](https://cran.r-project.org/package=discord)</br>
[![R-CMD-check](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-check.yaml)
[![Dev Main
branch](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-dev_check.yaml/badge.svg)](https://github.com/R-Computing-Lab/discord/actions/workflows/R-CMD-dev_check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/R-Computing-Lab/discord/graph/badge.svg)](https://app.codecov.io/gh/R-Computing-Lab/discord)
![License](https://img.shields.io/badge/License-GPL_v3-blue.svg)

<!-- badges: end -->

The goal of discord is to provide functions for discordant kinship
Expand Down
6 changes: 3 additions & 3 deletions man/rmvn.Rd → man/dot-rmvn.Rd

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

Loading