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
0 parents
commit a921e97
Showing
27 changed files
with
2,716 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Package: AnalysisLin | ||
Type: Package | ||
Title: Exploratory Data Analysis | ||
Version: 0.1.0 | ||
Authors@R: person("Zhiwei","Lin", ,"zhiweilin27@gmail.com",role = c("aut", "cre")) | ||
Description: A quick and effective data exploration toolkit. It provides essential features, including a descriptive statistics table for a quick overview of your dataset, interactive distribution plots to visualize variable patterns, Principal Component Analysis for dimensionality reduction and feature analysis, missing value imputation methods, and correlation analysis. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.3 | ||
Suggests: knitr, rmarkdown | ||
VignetteBuilder: knitr | ||
Date: 2024-01-22 | ||
Imports: Hmisc, ggplot2, plotly, stats, caret, htmltools, DT, magrittr, | ||
RANN | ||
NeedsCompilation: no | ||
Packaged: 2024-01-26 11:55:25 UTC; zhiweilin | ||
Author: Zhiwei Lin [aut, cre] | ||
Maintainer: Zhiwei Lin <zhiweilin27@gmail.com> | ||
Repository: CRAN | ||
Date/Publication: 2024-01-27 12:50:05 UTC |
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,2 @@ | ||
YEAR: 2023 | ||
COPYRIGHT HOLDER: AnalysisLin authors |
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,26 @@ | ||
f9b1d4d72fcbc2c971807e74195bce45 *DESCRIPTION | ||
c3b8c9073f1743068fe2f3c547e0c7ff *LICENSE | ||
b4a5434c562c8648e792d55ce0c19a43 *NAMESPACE | ||
a21c7c3ae3d9cef58c217e9c01471458 *R/corr_cluster.R | ||
c795b4327737a284ed5b0e9e538337d1 *R/corr_matrix.R | ||
2ae5d3c3b5701c193836a947e46ff52c *R/desc_stat.R | ||
4480be1d80c42d0095e10c25cadc738d *R/dist_plot.R | ||
bef1da2b503fd18c4fe44c9b0f1c8fcf *R/missing_impute.R | ||
c76a25d5f8ec69252ec26fe40c60a18c *R/missing_plot.R | ||
b2c914b0c2cdbf980e023f2a467415fb *R/pca.R | ||
bf77b7d497df5b503c425a31821d6467 *build/vignette.rds | ||
3e14a6e66f147c0cc49fcde8400887c3 *inst/doc/AnalysisLin-vignette.R | ||
02db1fe4ba7be8ab5fd4f922cc97b98c *inst/doc/AnalysisLin-vignette.Rmd | ||
fedd95f8a1758c247a42f0736fb7a725 *inst/doc/AnalysisLin-vignette.html | ||
b536d83b0a9a652f0971a2f6650d79c3 *man/bar_plot.Rd | ||
a6dbd5a2712c7dcc0386d9970d3900f9 *man/corr_cluster.Rd | ||
d1dabe155968e77e243559542b2e792b *man/corr_matrix.Rd | ||
525d244af067b7dcec62433aa5eada61 *man/dens_plot.Rd | ||
6d0b039d7f09cca6791802831abe8f06 *man/desc_stat.Rd | ||
8657757094ffe333142e955295e48eff *man/hist_plot.Rd | ||
d835c5994c7558b867019ca7e75b0096 *man/impute_missing.Rd | ||
f851eeecafee5f1a3fca9c498b245226 *man/missing_values_plot.Rd | ||
fe4ce64e7660b6fdbfa1c3dcdb2f0e9d *man/pca.Rd | ||
144145166e2238c299c254cb1d91e887 *man/pie_plot.Rd | ||
a40bad185149fad8840d64d9b34cee04 *man/qq_plot.Rd | ||
02db1fe4ba7be8ab5fd4f922cc97b98c *vignettes/AnalysisLin-vignette.Rmd |
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,32 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(bar_plot) | ||
export(corr_cluster) | ||
export(corr_matrix) | ||
export(dens_plot) | ||
export(desc_stat) | ||
export(hist_plot) | ||
export(impute_missing) | ||
export(missing_values_plot) | ||
export(pca) | ||
export(pie_plot) | ||
export(qq_plot) | ||
import(RANN) | ||
import(ggplot2) | ||
import(htmltools) | ||
import(magrittr) | ||
import(stats) | ||
importFrom(DT,datatable) | ||
importFrom(DT,formatStyle) | ||
importFrom(DT,styleInterval) | ||
importFrom(Hmisc,rcorr) | ||
importFrom(caret,preProcess) | ||
importFrom(grDevices,colors) | ||
importFrom(htmltools,tagList) | ||
importFrom(plotly,add_text) | ||
importFrom(plotly,add_trace) | ||
importFrom(plotly,colorbar) | ||
importFrom(plotly,ggplotly) | ||
importFrom(plotly,layout) | ||
importFrom(plotly,plot_ly) | ||
importFrom(plotly,style) |
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,26 @@ | ||
#' @title Correlation Clustering | ||
#' @description | ||
#' This function performs hierarchical clustering on a correlation matrix, providing insights into the relationships between variables. | ||
#' It generates a dendrogram visualizing the hierarchical clustering of variables based on their correlation patterns. | ||
#' | ||
#' @param data Input data frame. | ||
#' @param type The type of correlation to be computed. It can be "pearson", "kendall", or "spearman". | ||
#' @param method The method for hierarchical clustering. It can be "complete", "single", "average", "ward.D", "ward.D2", "mcquitty", "median", or "centroid". | ||
#' @param hclust_method The hierarchical clustering method. It can be "complete", "single", "average", "ward.D", "ward.D2", "mcquitty", "median", or "centroid". | ||
#' | ||
#' @return | ||
#' A dendrogram visualizing the hierarchical clustering of variables based on the correlation matrix. | ||
#' | ||
#' @examples | ||
#' data(mtcars) | ||
#' corr_cluster(data = mtcars, type = 'pearson', method = 'complete') | ||
#' | ||
#' @importFrom Hmisc rcorr | ||
#' @import stats | ||
#' @export | ||
corr_cluster <- function(data, type = 'pearson', method = 'complete', hclust_method = NULL) { | ||
corr <- Hmisc::rcorr(as.matrix(data), type = type)$r | ||
dist_matrix <- as.dist(1 - abs(corr)) | ||
hc <- hclust(dist_matrix, method = method) | ||
plot(hc, hang = -1, main = "Feature Distance") | ||
} |
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,93 @@ | ||
#' @title Correlation Matrix | ||
#' @description | ||
#' Column 1: Row names representing Variable 1 in the correlation test. | ||
#' | ||
#' Column 2: Column names representing Variable 2 in the correlation test. | ||
#' | ||
#' Column 3: The correlation coefficients quantifying the strength and direction of the relationship. | ||
#' | ||
#' Column 4: The p-values associated with the correlations, indicating the statistical significance | ||
#' of the observed relationships. Lower p-values suggest stronger evidence against the null hypothesis. | ||
#' | ||
#' The table provides valuable insights into the relationships between variables, helping to identify | ||
#' statistically significant correlations. | ||
#' | ||
#' @param data Input dataset. | ||
#' @param type Pearson or Spearman correlation, default is Pearson. | ||
#' @param corr_plot Generate a correlation matrix plot, default is false. | ||
#' @param sig.level Significant level. Default is 0.01. | ||
#' @param highlight Highlight p-value(s) that is less than sig.level, default is FALSE | ||
#' | ||
#' @return A data frame which contains row names, column names, correlation coefficients, and p-values. | ||
#' @return A plot of the correlation if corrplot is set to be true. | ||
#' | ||
#' @examples | ||
#' data(mtcars) | ||
#' corr_matrix(mtcars, type = 'pearson') | ||
#' @importFrom DT datatable formatStyle styleInterval | ||
#' @importFrom htmltools tagList | ||
#' @importFrom Hmisc rcorr | ||
#' @importFrom plotly plot_ly | ||
#' @importFrom plotly layout | ||
#' @importFrom plotly colorbar | ||
#' | ||
#' @export | ||
corr_matrix <- function(data, type = 'pearson', corr_plot = FALSE, sig.level = 0.01,highlight=FALSE) { | ||
result <- list() | ||
|
||
cormat <- Hmisc::rcorr(as.matrix(data), type = type)$r | ||
|
||
pmat <- Hmisc::rcorr(as.matrix(data), type = type)$P | ||
pmat[is.na(pmat)] <- 0 | ||
|
||
ut <- lower.tri(cormat) | ||
data <- data.frame( | ||
row = rownames(cormat)[row(cormat)[ut]], | ||
column = rownames(cormat)[col(cormat)[ut]], | ||
cor = cormat[ut], | ||
p = pmat[ut] | ||
) | ||
|
||
table1 <- DT::datatable( | ||
data, | ||
extensions = "Buttons", | ||
caption = "Correlation Table", | ||
options = list( | ||
dom = 'Blfrtip', | ||
buttons = c('copy', 'csv', 'excel', 'pdf'), | ||
paging = TRUE, | ||
searching = FALSE, | ||
ordering = TRUE, | ||
scrollX = TRUE | ||
), | ||
style = 'default', | ||
class = 'table-striped table-bordered' | ||
) | ||
|
||
if (highlight) { | ||
table1 <- table1 %>% | ||
formatStyle( | ||
columns = c("p"), | ||
valueColumns = c("p"), | ||
backgroundColor = styleInterval(0.05, c('yellow','transparent')) | ||
) | ||
} | ||
|
||
|
||
|
||
cormat[upper.tri(cormat)] <- NA | ||
pmat[upper.tri(cormat)] <- NA | ||
cormat[lower.tri(cormat)] <- ifelse(pmat[lower.tri(cormat)] < sig.level,cormat[lower.tri(cormat)], NA) | ||
plot <- plot_ly(z = cormat, x = rownames(cormat), y = colnames(cormat),, type = "heatmap", colorscale = "RdBu", reversescale = TRUE) %>% | ||
layout(title = "Correlation Heatmap", | ||
xaxis = list(title = "Variables", showgrid = FALSE), | ||
yaxis = list(title = "Variables", showgrid = FALSE))%>% | ||
colorbar(zmin = -1, zmax = 1) | ||
result <- htmltools::tagList() | ||
result$table <- table1 | ||
result$plot <- plot | ||
return(if (corr_plot) result else table1) | ||
} | ||
|
||
|
||
|
Oops, something went wrong.