Skip to content

Commit

Permalink
center
Browse files Browse the repository at this point in the history
  • Loading branch information
Carol-seven committed Jun 2, 2024
1 parent 31491c3 commit 78b5dcd
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 128 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(center)
export(preprocess)
export(transform)
import(dplyr)
import(ggplot2)
import(tidyr)
Expand Down
50 changes: 50 additions & 0 deletions R/center.R
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)
}
4 changes: 2 additions & 2 deletions R/globals.R
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
))
34 changes: 34 additions & 0 deletions R/meanVarPlot.R
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))
}
89 changes: 0 additions & 89 deletions R/transform.R

This file was deleted.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: '3.2'
pkgdown: 2.0.9
pkgdown_sha: ~
articles: {}
last_built: 2024-06-02T03:07Z
last_built: 2024-06-02T06:31Z
urls:
reference: https://uconn-scs.github.io/metastat/reference
article: https://uconn-scs.github.io/metastat/articles
Expand Down
91 changes: 91 additions & 0 deletions docs/reference/center.html

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

8 changes: 4 additions & 4 deletions docs/reference/index.html

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

Loading

0 comments on commit 78b5dcd

Please sign in to comment.