Skip to content

Commit ce9f5e1

Browse files
authored
Merge pull request #1 from DecodeGenetics/feature/fixing_checks
No issues in win dev or rhub
2 parents 3bc4179 + e244c0b commit ce9f5e1

39 files changed

Lines changed: 211 additions & 137 deletions

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
33
^LICENSE\.md$
4+
^README.Rmd
5+
^cran-comments\.md$

DESCRIPTION

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
Package: gnonadd
22
Type: Package
33
Title: Various Non-Additive Models for Genetic Associations
4-
Version: 1.0.0
4+
Version: 1.0.1
55
Authors@R: c(
66
person("Audunn S.", "Snaebjarnarson", , "audunn.snaebjarnarson@decode.is", role = c("aut", "cre")),
77
person("Gudmundur", "Einarsson", , "gudmundur.einarsson2@decode.is", role = c("aut")),
88
person("Daniel F.", "Gudbjartsson", , "daniel.gudbjartsson@decode.is", role = c("aut"))
99
)
1010
Description: The goal of gnonadd is to simplify workflows in the analysis of non-additive effects of
1111
sequence variants. This includes variance effects, correlation effects, interaction
12-
effects and dominance effects.
12+
effects and dominance effects. The package also includes convenience functions for visualization.
13+
URL: https://github.com/DecodeGenetics/gnonadd
14+
BugReports: https://github.com/DecodeGenetics/gnonadd/issues
1315
License: MIT + file LICENSE
1416
Encoding: UTF-8
1517
LazyData: true
1618
RoxygenNote: 7.2.1
1719
Depends:
1820
R (>= 2.10)
1921
Imports:
20-
ggplot2,
22+
ggplot2
23+
Suggests:
2124
MASS

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# gnonadd 1.0.1
2+
3+
* Added a `NEWS.md` file to track changes to the package.
4+
* Making package ready for initial CRAN release

R/Dominance_CaseControl_model.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' @param sex A numerical vector containing sex, coded 0 for males, 1 for females and -1 for unknown
1414
#' @param round_imputed A boolian variable determining whether imputed genotype values should be rounded to the nearest integer in the analysis
1515
#' @param covariates A dataframe containing any other covariates that should be used; one column per covariate.
16-
#'
16+
#'
1717
#' @returns
1818
#' A list with the dominanc effect (on log-scale) and corresponding standard error, z statistic and p-value
1919
#' @examples
@@ -39,11 +39,11 @@ dominance_CC.calc <- function(cc, g, yob=rep(-1,length(cc)), sex=rep(-1,length(c
3939
sex <- as.factor(sex)
4040
g <- g - mean(g)
4141
g2 <- as.numeric(g_rounded == 2)
42-
42+
4343
#We define a dataframe containing all variables that should be considered
4444
Dom_data <- as.data.frame(cbind(cc, g2))
4545
Dom_data <- cbind(Dom_data, g)
46-
if(sd(yob) > 0) {
46+
if(stats::sd(yob) > 0) {
4747
Dom_data <- cbind(Dom_data, yob)
4848
}
4949
if(length(unique(no_date)) > 1) {
@@ -55,15 +55,15 @@ dominance_CC.calc <- function(cc, g, yob=rep(-1,length(cc)), sex=rep(-1,length(c
5555
if(nrow(covariates) > 0) {
5656
Dom_data <- cbind(Dom_data, covariates)
5757
}
58-
58+
5959
#We use logistic regression to estimate the dominance effect
60-
l_delta <- glm(cc ~ ., data = Dom_data, family = 'binomial')
60+
l_delta <- stats::glm(cc ~ ., data = Dom_data, family = 'binomial')
6161
param <- "g2"
62-
if(param %in% rownames(coef(summary(l_delta)))){
62+
if(param %in% rownames(stats::coef(summary(l_delta)))){
6363
delta <- summary(l_delta)$coeff[param, 1]
6464
se <- summary(l_delta)$coeff[param, 2]
6565
z <- summary(l_delta)$coeff[param, 3]
66-
p <- summary(l_delta)$coeff[param, 4]
66+
p <- summary(l_delta)$coeff[param, 4]
6767
}else{
6868
warning("Singular model matrix")
6969
delta <- NA

R/Dominance_model.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @param g A vector with (possibly imputed) genotype values. All entries should be larger than 0 and smaller than 2.
1212
#' @param round_imputed A boolian variable determining whether imputed genotype values should be rounded to the nearest integer in the analysis
1313
#' @param covariates A dataframe containing any covariates that should be used; one column per covariate.
14-
#'
14+
#'
1515
#' @returns
1616
#' A list with the dominanc effect and corresponding standard error, t statistic and p-value
1717
#' @examples
@@ -32,22 +32,22 @@ dominance.calc <- function(qt, g, round_imputed = F, covariates = as.data.frame(
3232
p <- NA
3333
}else {
3434
g2 <- as.numeric(g_rounded == 2)
35-
35+
3636
#We define a dataframe containing all variables that should be considered
3737
Dom_data <- as.data.frame(cbind(qt, g2))
3838
Dom_data <- cbind(Dom_data, g)
3939
if(nrow(covariates) > 0) {
4040
Dom_data <- cbind(Dom_data, covariates)
4141
}
42-
42+
4343
#We use linear regression to estimate the dominance effect
44-
l_delta <- lm(qt ~ ., data = Dom_data)
44+
l_delta <- stats::lm(qt ~ ., data = Dom_data)
4545
param <- "g2"
46-
if(param %in% rownames(coef(summary(l_delta)))){
46+
if(param %in% rownames(stats::coef(summary(l_delta)))){
4747
delta <- summary(l_delta)$coeff[param, 1]
4848
se <- summary(l_delta)$coeff[param, 2]
4949
t <- summary(l_delta)$coeff[param, 3]
50-
p <- summary(l_delta)$coeff[param, 4]
50+
p <- summary(l_delta)$coeff[param, 4]
5151
}else{
5252
warning("Singular model matrix")
5353
delta <- NA

R/Ellipse_by_genotype.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
#' @export ellipse.by.gen
2525
ellipse.by.gen <- function(qt1, qt2, g, trait_name1 = 'qt trait 1', trait_name2 = 'qt trait 2',
2626
title = '', sample_size = 500) {
27+
g_factor <- NULL
28+
x0 <- NULL
29+
x1 <- NULL
30+
x2 <- NULL
31+
y0 <- NULL
32+
y1 <- NULL
33+
y2 <- NULL
2734
g <- round(g)
2835
D <- cbind(qt1, qt2)
2936
D <- cbind(D, g)
@@ -42,7 +49,7 @@ ellipse.by.gen <- function(qt1, qt2, g, trait_name1 = 'qt trait 1', trait_name2
4249
D_sample <- rbind(D_sample, D_temp[sample(1:nrow(D_temp), size = min(sample_size, nrow(D_temp)), replace = FALSE), ])
4350
qt1_mean <- mean(D_temp$qt1)
4451
qt2_mean <- mean(D_temp$qt2)
45-
Sigma <- cov(D_temp[, c(1, 2)])
52+
Sigma <- stats::cov(D_temp[, c(1, 2)])
4653
Princip <- eigen(Sigma)
4754
flip_direction1 <- 0
4855
flip_direction2 <- 0
@@ -66,7 +73,7 @@ ellipse.by.gen <- function(qt1, qt2, g, trait_name1 = 'qt trait 1', trait_name2
6673
}
6774
ggplot2::ggplot(D_sample, ggplot2::aes(x = qt1 , y = qt2 ,color = g_factor))+
6875
ggplot2::geom_point()+ggplot2::theme_classic()+
69-
ggplot2::geom_smooth(method = 'lm', data = D, se = F, formula = as.formula('y ~ x')) +
76+
ggplot2::geom_smooth(method = 'lm', data = D, se = F, formula = stats::as.formula('y ~ x')) +
7077
ggplot2::coord_fixed() +
7178
ggplot2::scale_color_manual(values = c('Non-carriers' = '#F8766D', 'Heterozygotes' = '#00BA38', 'Homozygotes' = '#619CFF')) +
7279
ggplot2::geom_segment(ggplot2::aes(x = Arrow_data[1, 1], y = Arrow_data[1, 2],

R/Env_interaction_CaseControl_all_vs_all.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' @description
44
#' Given a set of variants and environmental traits, and a single case control variable, this function calculates the interaction effect of all possible variant-environmental pairs
5-
#'
5+
#'
66
#' @param cc A numeric vector
77
#' @param g A matrix, where each colomn represents a variant
88
#' @param env A matrix, where each row represents an environmental variable
@@ -18,16 +18,19 @@
1818
#' @returns
1919
#' A dataframe with all possible variant-environmental pairs and their estimated interaction effect
2020
#' @examples
21-
#' g_vec <- matrix(0, nrow = 100000, ncol = 3)
21+
#' N_run <- 25000
22+
#' g_vec <- matrix(0, nrow = N_run, ncol = 3)
2223
#' freqs <- runif(ncol(g_vec), min = 0, max = 1)
23-
#' env_vec <- matrix(0, nrow = 100000, ncol = 3)
24+
#' env_vec <- matrix(0, nrow = N_run, ncol = 3)
2425
#' for(i in 1:ncol(g_vec)){
25-
#' g_vec[, i] <- rbinom(100000, 2, freqs[i])
26+
#' g_vec[, i] <- rbinom(N_run, 2, freqs[i])
2627
#' }
2728
#' for( i in 1:ncol(env_vec)){
28-
#' env_vec[, i] <- round(runif(100000,min=0,max=6))
29+
#' env_vec[, i] <- round(runif(N_run,min=0,max=6))
2930
#' }
30-
#' cc_vec <- rbinom(100000,1,0.1 * (1.05 ^ g_vec[, 1]) * (1.06 ^ env_vec[,1]) * (0.95 ^ g_vec[, 2]) * (1.1^(g_vec[, 1] * env_vec[, 1])))
31+
#' cc_vec <- rbinom(N_run,1,0.1 * (1.05 ^ g_vec[, 1]) *
32+
#' (1.06 ^ env_vec[,1]) * (0.95 ^ g_vec[, 2]) *
33+
#' (1.1^(g_vec[, 1] * env_vec[, 1])))
3134
#' res <- pairwise_env_int_CC.calc(cc_vec, g_vec, env_vec)
3235
#' @export
3336
pairwise_env_int_CC.calc <- function(cc, g, env, yob = rep(-1,length(cc)), sex = rep(-1,length(cc)),
@@ -44,7 +47,7 @@ pairwise_env_int_CC.calc <- function(cc, g, env, yob = rep(-1,length(cc)), sex =
4447
counter <- counter + 1
4548
A$variant_name[counter] <- variant_names[i]
4649
A$env_name[counter] <- env_names[j]
47-
res <- env_interaction_CC.calc(cc, g[, i], env[, j], yob = yob, sex = sex,
50+
res <- env_interaction_CC.calc(cc, g[, i], env[, j], yob = yob, sex = sex,
4851
round_imputed = round_imputed, dominance_term = dominance_term, square_env = square_env, covariates = covariates )
4952
A$int_effect[counter] <- res$interaction_effect
5053
A$se[counter] <- res$standard_error

R/Env_interaction_model.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' @param dominance_term A boolian variable determining whether a dominance term for the variant should be included as a covariates in the analysis
1717
#' @param square_env A boolian variable determining whether the square of the environmental trait should be included as a covariate in the analysis
1818
#' @param covariates A dataframe containing any other covariates that should be used; one column per covariate
19-
#'
19+
#'
2020
#' @returns
2121
#' A list with the environmental interaction effect and corresponding standard error, t statistic and p-value
2222
#' @examples
@@ -28,19 +28,19 @@
2828
env_interaction.calc <- function(qt, g, env, round_imputed = F, dominance_term = F,
2929
square_env = F, covariates = as.data.frame(matrix(0, nrow = 0, ncol = 0))){
3030
r <- rank(env)
31-
env_normal <- qnorm(r / (length(r) + 1))
31+
env_normal <- stats::qnorm(r / (length(r) + 1))
3232
if(round_imputed == T){
3333
g <- round(g)
3434
}
3535
int <- g * env_normal
36-
if(sd(int) == 0){
36+
if(stats::sd(int) == 0){
3737
warning("Interaction undefined. All interaction values are the same.")
3838
gamma <- NA
3939
se <- NA
4040
t <- NA
4141
p <- NA
4242
}else{
43-
43+
4444
#We define a dataframe containing all variables that should be considered
4545
Env_int_data <- as.data.frame(cbind(qt, int))
4646
Env_int_data <- cbind(Env_int_data, g)
@@ -54,15 +54,15 @@ env_interaction.calc <- function(qt, g, env, round_imputed = F, dominance_term =
5454
if(nrow(covariates) > 0) {
5555
Env_int_data <- cbind(Env_int_data, covariates)
5656
}
57-
57+
5858
#We use linear regression to estimate the environmental interaction effect
59-
l_interaction <- lm(qt ~ ., data = Env_int_data)
59+
l_interaction <- stats::lm(qt ~ ., data = Env_int_data)
6060
param <- "int"
61-
if(param %in% rownames(coef(summary(l_interaction)))){
61+
if(param %in% rownames(stats::coef(summary(l_interaction)))){
6262
gamma <- summary(l_interaction)$coeff[param, 1]
6363
se <- summary(l_interaction)$coeff[param, 2]
6464
t <- summary(l_interaction)$coeff[param, 3]
65-
p <- summary(l_interaction)$coeff[param, 4]
65+
p <- summary(l_interaction)$coeff[param, 4]
6666
}else{
6767
warning("Singular model matrix")
6868
gamma <- NA

R/Env_interactions_all_vs_all.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#' env_vec[, i] <- round(runif(100000,min=0,max=6))
2828
#' }
2929
#'
30-
#' qt_vec <- rnorm(100000) + 0.1 * g_vec[, 1] + 0.2 * g_vec[, 2] -0.1 * env_vec[, 3] + 0.1 * env_vec[, 1] + 0.1 * g_vec[, 1] * env_vec[, 1]
30+
#' qt_vec <- rnorm(100000) + 0.1 * g_vec[, 1] + 0.2 *
31+
#' g_vec[, 2] -0.1 * env_vec[, 3] + 0.1 *
32+
#' env_vec[, 1] + 0.1 * g_vec[, 1] * env_vec[, 1]
3133
#' res <- pairwise_env_int.calc(qt_vec, g_vec, env_vec)
3234
#' @export
3335
pairwise_env_int.calc <- function(qt, g, env, round_imputed = F, dominance_term = F, square_env = F,

R/Histogram_by_genotype.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
#' hist_by_gen(qt_vec, geno_vec)
2222
#' @export hist_by_gen
2323
hist_by_gen <- function(qt, g, bins = 100, trait_name = 'qt trait', title = '', outlier_quantiles = c(0.025, 0.975), sd_lines = c(1,1)) {
24+
outlier <- NULL
2425
g <- round(g)
2526
D <- as.data.frame(cbind(qt,g))
2627
D$g_factor <- factor(D$g,levels=0:2, labels = c('Non-carriers', 'Heterozygotes', 'Homozygotes'))
27-
quant_vals <- as.numeric(quantile(D$qt, outlier_quantiles))
28+
quant_vals <- as.numeric(stats::quantile(D$qt, outlier_quantiles))
2829
D$outlier <- as.factor(0+(D$qt<quant_vals[1] | D$qt > quant_vals[2]))
2930
a <- sd_lines[1]
3031
b <- sd_lines[2]
3132
vertical_lines <- data.frame(g_factor = levels(D$g_factor), mean = c(mean(D$qt[D$g == 0]), mean(D$qt[D$g == 1]), mean(D$qt[D$g == 2])),
32-
lower_sd <- c(mean(D$qt[D$g == 0]) - a * sd(D$qt[D$g == 0]), mean(D$qt[D$g == 1]) - a * sd(D$qt[D$g == 1]), mean(D$qt[D$g == 2]) - a * sd(D$qt[D$g == 2])),
33-
upper_sd <- c(mean(D$qt[D$g == 0]) + b * sd(D$qt[D$g == 0]), mean(D$qt[D$g == 1]) + b * sd(D$qt[D$g == 1]), mean(D$qt[D$g == 2]) + b * sd(D$qt[D$g == 2])))
33+
lower_sd <- c(mean(D$qt[D$g == 0]) - a * stats::sd(D$qt[D$g == 0]), mean(D$qt[D$g == 1]) - a * stats::sd(D$qt[D$g == 1]), mean(D$qt[D$g == 2]) - a * stats::sd(D$qt[D$g == 2])),
34+
upper_sd <- c(mean(D$qt[D$g == 0]) + b * stats::sd(D$qt[D$g == 0]), mean(D$qt[D$g == 1]) + b * stats::sd(D$qt[D$g == 1]), mean(D$qt[D$g == 2]) + b * stats::sd(D$qt[D$g == 2])))
3435

3536
ggplot2::ggplot(D, ggplot2::aes(x = qt, fill = outlier)) + ggplot2::geom_histogram(color = 'black', bins = bins) + ggplot2::theme_classic() +
3637
ggplot2::facet_grid(g_factor ~ . , scales = "free_y") + ggplot2::xlab(trait_name) + ggplot2::ggtitle(title) +

0 commit comments

Comments
 (0)