-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implement a function to remove constant metrics and categorical metrics - Implement a function to get correlation groups according to VarClus
- Loading branch information
Jirayus
committed
Mar 25, 2019
1 parent
a692a3e
commit 16baa39
Showing
7 changed files
with
119 additions
and
19 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
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 @@ | ||
#' Check for constant metrics and categorical metrics | ||
#' | ||
#' @param dataset a data frame for data | ||
#' @param metrics a characters or a vector of characters for independent variables | ||
#' @keywords constant categorical | ||
#' @examples | ||
#' Data = loadDefectDataset('groovy-1_5_7','jira') | ||
#' check.constant.categorical(dataset = Data$data, metrics = Data$indep) | ||
#' @export | ||
check.constant.categorical <- | ||
function(dataset, | ||
metrics) { | ||
# Check constant metrics | ||
constant <- | ||
apply(dataset[, metrics], 2, function(x) | ||
max(x) == min(x)) | ||
constant <- names(constant[constant == TRUE]) | ||
# Remove constant metrics | ||
if (length(constant) > 0) { | ||
metrics <- metrics[!metrics %in% constant] | ||
} | ||
|
||
# Check categorical metrics | ||
category <- sapply(dataset[, metrics], class) | ||
category <- names(category[category == "character"]) | ||
# Remove categorical metrics from Spearman Analysis | ||
if (length(category) > 0) { | ||
metrics <- metrics[!metrics %in% category] | ||
} | ||
|
||
return(metrics) | ||
} |
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,30 @@ | ||
#' Get correlation groups according to VarClus based on the absolute Spearman correlation coefficients between metrics | ||
#' | ||
#' This function makes life simple by providing a VarClus. | ||
#' @param dataset a data frame for data | ||
#' @param metrics a vector of characters or a vector of characters for independent variables | ||
#' @param similarity a character for similarity measures (e.g., Spearman rank correlation), default = spearman | ||
#' @param varclus.threshold a numeric for correlation coefficient threshold value | ||
#' @importFrom Hmisc varclus | ||
#' @keywords VarClus | ||
|
||
get.vc.correlation.groups <- function(dataset, metrics, similarity = 'spearman', varclus.threshold = 0.7){ | ||
|
||
# Check constant metrics and categorical metrics | ||
metrics <- check.constant.categorical(dataset, metrics) | ||
|
||
f <- as.formula(paste("~", paste(metrics, collapse = " + "))) | ||
vc <- | ||
Hmisc::varclus(f, | ||
similarity = similarity, | ||
data = dataset[, metrics], | ||
trans = "abs") | ||
|
||
var.clusters <- | ||
cutree(vc$hclust, h = (1 - varclus.threshold)) | ||
melted.data <- melt(var.clusters) | ||
varclus.correlation.groups <- data.frame(metrics = row.names(melted.data), rank = var.clusters) | ||
row.names(varclus.correlation.groups) <- NULL | ||
|
||
return(varclus.correlation.groups) | ||
} |
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.