-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31491c3
commit 78b5dcd
Showing
12 changed files
with
215 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' | ||
#' Centering | ||
#' | ||
#' @description | ||
#' Apply centering to the data. | ||
#' | ||
#' @param dataSet A data frame containing the data signals. | ||
#' | ||
#' @param names A vector of strings (default = c("gender", "treatment", "replicate")) | ||
#' specifying the names of the attribute columns. | ||
#' | ||
#' @details | ||
#' The function executes the following: | ||
#' \enumerate{ | ||
#' \item Plots the mean-variance relationship. | ||
#' \item Centers the data. | ||
#' \item Plots the mean-variance relationship again for comparison. | ||
#' } | ||
#' | ||
#' @returns The centered data. | ||
#' | ||
#' @autoglobal | ||
#' | ||
#' @export | ||
|
||
center <- function(dataSet, | ||
names = c("gender", "treatment", "replicate")) { | ||
|
||
## organize the data for centering | ||
dataPoints <- dataSet %>% | ||
select(-any_of(names)) | ||
|
||
## calculate and plot a mean-variance plot | ||
plotPre <- meanVarPlot(dataPoints, title = "Pre-Centering") | ||
print(plotPre) | ||
|
||
## centering | ||
centerData <- colMeans(dataPoints, na.rm=TRUE) | ||
centeredDataPoints <- sweep(dataPoints, 2L, centerData, check.margin = FALSE) | ||
|
||
## calculate and plot a mean-variance plot | ||
plotPost <- meanVarPlot(centeredDataPoints, title = "Post-Centering") | ||
print(plotPost) | ||
|
||
## recombine the labels and centered data into a single data frame | ||
centeredDataSet <- cbind(dataSet[,names], centeredDataPoints) | ||
|
||
## return the centered data | ||
return(centeredDataSet) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Generated by roxyglobals: do not edit by hand | ||
|
||
utils::globalVariables(c( | ||
"Compound", # <preprocess> | ||
"name", # <preprocess> | ||
"Mean", # <meanVarPlot> | ||
"Variance", # <meanVarPlot> | ||
"Compound", # <preprocess> | ||
"name", # <preprocess> | ||
NULL | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' | ||
#' Plotting a graph of mean versus variance | ||
#' | ||
#' @description | ||
#' Take a set of metabolics data organized by column, calculate the mean and variance of | ||
#' each column, and then plot those statistics. | ||
#' | ||
#' @param datMV A data frame containing the data signals. | ||
#' | ||
#' @param title A string with the desired title for the mean-variance plot. | ||
#' | ||
#' @import ggplot2 | ||
#' @importFrom stats var median | ||
#' | ||
#' @returns An object of class \code{plot}. | ||
#' | ||
#' @autoglobal | ||
#' | ||
#' @noRd | ||
|
||
meanVarPlot <- function(datMV, title = "") { | ||
|
||
## calculate the mean and variance for each protein individually | ||
plotData <- data.frame(t(sapply(datMV, function(x) { | ||
c(Mean = mean(x, na.rm = TRUE), Variance = var(x, na.rm = TRUE)) | ||
}))) | ||
|
||
## plot the mean-variance relationship | ||
ggplot(plotData, aes(Mean, Variance)) + | ||
geom_point() + | ||
labs(title = title) + | ||
theme_bw() + | ||
theme(plot.title = element_text(hjust = 0.5)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.