Skip to content

Commit

Permalink
drafting the main function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonfparil committed Jun 5, 2024
1 parent b872d94 commit 468e709
Show file tree
Hide file tree
Showing 27 changed files with 2,579 additions and 679 deletions.
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ export(fn_G_numeric_to_non_numeric)
export(fn_G_split_off_alternative_allele)
export(fn_G_to_vcf)
export(fn_classify_allele_frequencies)
export(fn_cross_validation_across_populations_bulk)
export(fn_cross_validation_across_populations_lopo)
export(fn_cross_validation_across_populations_pairwise)
export(fn_cross_validation_preparation)
export(fn_cross_validation_within_population)
export(fn_cv_1)
export(fn_elastic_net)
export(fn_estimate_memory_footprint)
export(fn_filter_genotype)
export(fn_filter_phenotype)
export(fn_gBLUP)
Expand All @@ -24,4 +30,5 @@ export(fn_ridge)
export(fn_save_genotype)
export(fn_save_phenotype)
export(fn_simulate_data)
export(fn_subset_merged_genotype_and_phenotype)
export(fn_vcf_to_G)
2,178 changes: 1,569 additions & 609 deletions R/cross_validation.R

Large diffs are not rendered by default.

174 changes: 157 additions & 17 deletions R/io.R

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion R/metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#'
#' @param y_true numeric vector observed phenotype values
#' @param y_pred numeric vector predicted phenotype values
#' @param verbose show genomic prediction performance metric calculation messages? (Default=FALSE)
#' @returns
#' Ok:
#' $mbe: mean bias error
Expand Down Expand Up @@ -69,7 +70,7 @@ fn_prediction_performance_metrics = function(y_true, y_pred, verbose=FALSE) {
} else {
r2 = 1 - (sum(error^2, na.rm=TRUE) / sum((y_true-mean(y_true, na.rm=TRUE))^2, na.rm=TRUE))
}
corr = suppressWarnings(stats::cor(y_true, y_pred, method="pearson"))
corr = suppressWarnings(stats::cor(y_true, y_pred, method="pearson", use="na.or.complete"))
### Power to select true top and bottom 10%
n_top_or_bottom_10 = max(c(1, round(0.1*n)))
top10_dec_true = order(y_true, decreasing=TRUE)[1:n_top_or_bottom_10]
Expand Down
16 changes: 12 additions & 4 deletions R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ fn_ols = function(list_merged, vec_idx_training, vec_idx_validation, other_param
}
X_training = list_merged$G[vec_idx_training, ]
y_training = list_merged$list_pheno$y[vec_idx_training]
X_training = X_training[!is.na(y_training), ] ### Remove missing phenotype data from the training set
y_training = y_training[!is.na(y_training)] ### Remove missing phenotype data from the training set
X_validation = list_merged$G[vec_idx_validation, ]
y_validation = list_merged$list_pheno$y[vec_idx_validation]
### Adding covariate to explanatory matrix
Expand Down Expand Up @@ -275,6 +277,8 @@ fn_ridge = function(list_merged, vec_idx_training, vec_idx_validation, other_par
}
X_training = list_merged$G[vec_idx_training, ]
y_training = list_merged$list_pheno$y[vec_idx_training]
X_training = X_training[!is.na(y_training), ] ### Remove missing phenotype data from the training set
y_training = y_training[!is.na(y_training)] ### Remove missing phenotype data from the training set
X_validation = list_merged$G[vec_idx_validation, ]
y_validation = list_merged$list_pheno$y[vec_idx_validation]
### Adding covariate to explanatory matrix
Expand Down Expand Up @@ -416,6 +420,8 @@ fn_lasso = function(list_merged, vec_idx_training, vec_idx_validation, other_par
}
X_training = list_merged$G[vec_idx_training, ]
y_training = list_merged$list_pheno$y[vec_idx_training]
X_training = X_training[!is.na(y_training), ] ### Remove missing phenotype data from the training set
y_training = y_training[!is.na(y_training)] ### Remove missing phenotype data from the training set
X_validation = list_merged$G[vec_idx_validation, ]
y_validation = list_merged$list_pheno$y[vec_idx_validation]
### Adding covariate to explanatory matrix
Expand Down Expand Up @@ -557,6 +563,8 @@ fn_elastic_net = function(list_merged, vec_idx_training, vec_idx_validation, oth
}
X_training = list_merged$G[vec_idx_training, ]
y_training = list_merged$list_pheno$y[vec_idx_training]
X_training = X_training[!is.na(y_training), ] ### Remove missing phenotype data from the training set
y_training = y_training[!is.na(y_training)] ### Remove missing phenotype data from the training set
X_validation = list_merged$G[vec_idx_validation, ]
y_validation = list_merged$list_pheno$y[vec_idx_validation]
### Adding covariate to explanatory matrix
Expand Down Expand Up @@ -747,8 +755,8 @@ fn_Bayes_A = function(list_merged, vec_idx_training, vec_idx_validation,
}

#' Bayes B regression model
#' (scaled t-distributed effects with probability $\pi$; and zero effects with probability $1-\pi$,
#' where $\pi \sim \beta(\theta_1, \theta_2)$)
#' (scaled t-distributed effects with probability \eqn{\pi}; and zero effects with probability \eqn{1-\pi},
#' where \eqn{\pi \sim \beta(\theta_1, \theta_2)})
#'
#' @param list_merged list of merged genotype matrix, and phenotype vector, as well as an optional covariate matrix
#' $G: numeric n samples x p loci-alleles matrix of allele frequencies with non-null row and column names.
Expand Down Expand Up @@ -889,8 +897,8 @@ fn_Bayes_B = function(list_merged, vec_idx_training, vec_idx_validation,
}

#' Bayes C regression model
#' (normally distributed effects ($N(0, \sigma^2_{\beta})$) with probability $\pi$; and zero effects
#' with probability $1-\pi$, where $\pi \sim \beta(\theta_1, \theta_2)$)
#' (normally distributed effects (\eqn{N(0, \sigma^2_{\beta})}) with probability \eqn{\pi}; and zero effects
#' with probability \eqn{1-\pi}, where \eqn{\pi \sim \beta(\theta_1, \theta_2)})
#'
#' @param list_merged list of merged genotype matrix, and phenotype vector, as well as an optional covariate matrix
#' $G: numeric n samples x p loci-alleles matrix of allele frequencies with non-null row and column names.
Expand Down
7 changes: 5 additions & 2 deletions man/fn_Bayes_A.Rd

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

15 changes: 9 additions & 6 deletions man/fn_Bayes_B.Rd

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

15 changes: 9 additions & 6 deletions man/fn_Bayes_C.Rd

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

118 changes: 118 additions & 0 deletions man/fn_cross_validation_across_populations_bulk.Rd

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

Loading

0 comments on commit 468e709

Please sign in to comment.