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
cbb13a9
commit 5f9dd45
Showing
39 changed files
with
1,392 additions
and
257 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 |
---|---|---|
@@ -1,34 +1,44 @@ | ||
d93e9ea4f3251e51aff2c3e4be04bb8b *DESCRIPTION | ||
055726a3bc8ef0bcc8453543471f0b5e *NAMESPACE | ||
bddf4091c54589c77ef555e7601956e3 *NEWS.md | ||
56ce9b1f5cfd79e1895907e7d82c7e38 *DESCRIPTION | ||
c28ad3214e9621d02eea369168de6f51 *NAMESPACE | ||
32c4defdfcdaf98d0ef18debd5a66cab *NEWS.md | ||
3d99d2c6e7b65740c7ad8a6d1d7d0ef3 *R/assumptionCheck.R | ||
5bd9fbab2b62362b990fe24b85807cad *R/bridge.R | ||
db9fae5fe89d0a82e7a600227a65791e *R/data_documentation.R | ||
8df274acbd65c21842c6feae69c9c292 *R/edge_impact.R | ||
6d61886bfbe2c4d691cee455837c6f70 *R/expectedInf.R | ||
2fb9555af1d5f602787fa2f4812144f6 *R/global_impact.R | ||
4d207de152befddd17a1ab8b1459e851 *R/hidden_functions.R | ||
6b8b5a97c572b3563093dcbafa691e39 *R/impact.R | ||
e4591f67a8ee8260f5d0302a96c13d25 *R/impact_NCT.R | ||
bbd3d74e355b964e4ac70407fae1b548 *R/structure_impact.R | ||
d4cb6f162e29b899919ded963232622b *R/summary_print_plot.R | ||
8a65e26936a057b6f6a39bde8315c3b2 *build/vignette.rds | ||
9749b1badaa667b773d82e9af8708ec5 *R/edge_impact.R | ||
145a2e5fd3c7c6371f91fcfa706b1435 *R/expectedInf.R | ||
b2885be98c23ad6c55ff538baaf3fcd8 *R/global_impact.R | ||
231ede57b79c0d39446d959f96737ca8 *R/hidden_functions.R | ||
1c85bff098685d22d00a14eb9888532e *R/impact.R | ||
40fe130ee122e9688390176d3b8442e9 *R/impact_NCT.R | ||
27ee303b044436d7f57fb0f90014ae7d *R/impact_boot.R | ||
f19d1aae4aca9e5cb9c6f2f960007e79 *R/networktools-package.r | ||
0b8b93933f1459e0d9f5d95397de60ba *R/structure_impact.R | ||
551bb5c7ce62d61b6c539d4535ea08b8 *R/summary_print_plot.R | ||
847f24ed61e7a07d1101b122ff7cbfba *build/vignette.rds | ||
b36c9ac17ed19012e016f719d89696a0 *data/depression.rda | ||
089c6b27af88285ef845229c2e78467e *data/social.rda | ||
3d453e9c6cb2cac3c29c76386195efea *inst/doc/Impact.R | ||
728388b55a75abf098bfe481d231b714 *inst/doc/Impact.Rmd | ||
c827e58f1d0f7fbd53affe6a21b72894 *inst/doc/Impact.pdf | ||
b1752dd14d507b01dadef5b00c451e7d *inst/doc/networktools.pdf | ||
3db79a48f7a5dd0c2ac19d5ff25d4210 *inst/doc/Impact.R | ||
49ac028ced27a0ea43180c810ee65886 *inst/doc/Impact.Rmd | ||
a5f4d37386c393ee9f8c9ab51cecc49a *inst/doc/Impact.pdf | ||
913a0e069d33326c12d0171058d3ca89 *inst/doc/networktools.pdf | ||
44951a88c1e44e76cac482e007d3abe4 *man/assumptionCheck.Rd | ||
411819868208601ad5e8605f0d2553c2 *man/bridge.Rd | ||
2f3c7f986b69779336f92dd4da52d43e *man/coerce_to_adjacency.Rd | ||
6b369dc2cc0ed86fa1f64b081c09b78a *man/depression.Rd | ||
ddeea37d0e573c342f84086a1944fda1 *man/edge.impact.Rd | ||
973979c2b8a3aa490f81f7ad3de76a2e *man/edge.impact.Rd | ||
c006aa48ab73bfabb3879dcc024cbe58 *man/expectedInf.Rd | ||
eb1a7a9e16423d8023c9f10cff74e635 *man/global.impact.Rd | ||
575ae83357ec70f5f21242f21777a201 *man/impact.NCT.Rd | ||
e84ebcd86e39628e59faae4fafd55e45 *man/impact.Rd | ||
654fe7e72cb11211412fce92006f6796 *man/plot.all.impact.Rd | ||
954d62892e71c27741c2dfca5b53abeb *man/plot.edge.impact.Rd | ||
611b36e1c85f71f37333b469157334c9 *man/plot.expectedInf.Rd | ||
9729b3940a2b8057f2ff99d9fee613ce *man/plot.global.impact.Rd | ||
c1f63b6cb912ff538a8ada0d734da89e *man/plot.structure.impact.Rd | ||
dfbd199423233683e1d46374d5f401c9 *man/global.impact.Rd | ||
2fc456793c379430e12378b37ee2407f *man/impact.NCT.Rd | ||
00cb8a470e756a614b7378773339d5f5 *man/impact.Rd | ||
e860314e7d136e76e43e6ac589b2c489 *man/impact.boot.Rd | ||
1156dead634fe0c301412661d9ecdfc6 *man/networktools.Rd | ||
622dc6d76e9c19cedbd971963dd8a130 *man/plot.all.impact.Rd | ||
dda646c0e050f98b4e9c802b9b6054c8 *man/plot.bridge.Rd | ||
16cb20ca730dcd91fdc64d7236f5e04d *man/plot.edge.impact.Rd | ||
29c614a613fd8dc24f48db94883d489a *man/plot.expectedInf.Rd | ||
d1425df1dc7d666b82e32ca2ce3c07fb *man/plot.global.impact.Rd | ||
8d8c76b274704cb0f52f0dce98c260a2 *man/plot.structure.impact.Rd | ||
1077043d1e1e5092559f7acdb02205db *man/social.Rd | ||
8e68c2e1fd94634f929fec7e3e2d00a8 *man/structure.impact.Rd | ||
dd372fe9c671fde73411860508224e1b *vignettes/Impact.Rmd | ||
7141c865408c67ff78ffaf4d74359e88 *vignettes/figures/pe_figure.png | ||
e5bea2ea7a637816fa7f527e8df55249 *man/structure.impact.Rd | ||
49ac028ced27a0ea43180c810ee65886 *vignettes/Impact.Rmd | ||
41d8ebd21578934b1c0fd6fa944dc9ad *vignettes/figures/pe_figure.png |
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,23 +1,30 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(plot,all.impact) | ||
S3method(plot,bridge) | ||
S3method(plot,edge.impact) | ||
S3method(plot,expectedInf) | ||
S3method(plot,global.impact) | ||
S3method(plot,structure.impact) | ||
S3method(print,all.impact) | ||
S3method(print,bridge) | ||
S3method(print,edge.impact) | ||
S3method(print,expectedInf) | ||
S3method(print,global.impact) | ||
S3method(print,structure.impact) | ||
S3method(summary,all.impact) | ||
S3method(summary,bridge) | ||
S3method(summary,edge.impact) | ||
S3method(summary,expectedInf) | ||
S3method(summary,global.impact) | ||
S3method(summary,structure.impact) | ||
export(assumptionCheck) | ||
export(bridge) | ||
export(coerce_to_adjacency) | ||
export(edge.impact) | ||
export(expectedInf) | ||
export(global.impact) | ||
export(impact) | ||
export(impact.NCT) | ||
export(impact.boot) | ||
export(structure.impact) |
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,123 @@ | ||
#' Assumption Checking Function | ||
#' | ||
#' Checks some basic assumptions about the suitability of network analysis on | ||
#' your data | ||
#' | ||
#' This function is in BETA. Please report any errors. | ||
#' | ||
#' @param data dataframe or matrix of observational data (rows: observations, columns: nodes) | ||
#' @param type which assumptions to check? "network" tests the suitability for | ||
#' network analysis in general. "impact" tests the suitability for analyzing impact | ||
#' @param percent percent difference from grand mean that is acceptable when comparing variances. | ||
#' @param split if type="impact", specifies the type of split to utilize | ||
#' @param plot logical. Should histograms each variable be plotted? | ||
#' @param binary.data logical. Defaults to FALSE | ||
#' @param na.rm logical. Should missing values be removed? | ||
#' | ||
#' @details | ||
#' | ||
#' Network analysis rests on several assumptions. Among these: | ||
#' - Variance of each node is (roughly) equal | ||
#' - Distributions are (roughly) normal | ||
#' | ||
#' Comparing networks in impact rests on additional assumptions including: | ||
#' - Overall variances are (roughly) equal in each half | ||
#' | ||
#' This function checks these assumptions and notifies any violations. | ||
#' This function is not intended as a substitute for careful data visualization | ||
#' and independent assumption checks. | ||
#' | ||
#' See citations in the references section for further details. | ||
#' | ||
#' @references | ||
#' | ||
#' Terluin, B., de Boer, M. R., & de Vet, H. C. W. (2016). Differences in Connection Strength between Mental Symptoms Might Be Explained by Differences in Variance: Reanalysis of Network Data Did Not Confirm Staging. PLOS ONE, 11(11), e0155205. Retrieved from https://doi.org/10.1371/journal.pone.0155205 | ||
#' | ||
#' @export | ||
assumptionCheck <- function(data, type=c("network", "impact"), percent=20, | ||
split=c("median","mean", "forceEqual", "cutEqual", "quartiles"), | ||
plot=FALSE, binary.data=FALSE, na.rm=TRUE) { | ||
if(match.arg(type)=="network"){ | ||
varNodes <- apply(data, 2, stats::var, na.rm=na.rm) | ||
normNodes <- apply(data, 2, stats::shapiro.test) | ||
normNodes <- as.numeric(sapply(normNodes,`[`,2)) | ||
varviolNodes <- vector() | ||
normviolNodes <- vector() | ||
if(is.null(colnames(data))) {colnames(data) <- 1:dim(data)[2]} | ||
names(normNodes) <- names(varNodes)<-colnames(data) | ||
grandMean <- mean(varNodes) | ||
for(i in 1:length(varNodes)) { | ||
if(abs((varNodes[i]/grandMean)-1)>(percent/100)) {varviolNodes[i] <- names(varNodes[i])} | ||
if(normNodes[i]<0.01) {normviolNodes[i] <- names(varNodes[i])} | ||
} | ||
varviolNodes <- stats::na.omit(varviolNodes) | ||
normviolNodes <- stats::na.omit(normviolNodes) | ||
if(length(varviolNodes != 0)) {message("Equal node variance violation: variance of the following nodes differs more than ", | ||
percent, "% from grand mean: \n", paste0(varviolNodes, sep=" "), "\n")} | ||
if(length(normviolNodes != 0)) {message("Shapiro-Wilk violation (p<0.01): Visually check normality of nodes: \n", | ||
paste0(normviolNodes, sep=" "), "\n")} | ||
cat("Grand mean of variances = ", grandMean, "\n") | ||
cat("Node variances \n") | ||
print(varNodes) | ||
cat("\n Shapiro-Wilk Normality (p) \n") | ||
print(normNodes) | ||
if(plot){ | ||
op <- graphics::par(mfrow=c(round((dim(data)[2]/3)+.5), 3)) | ||
for(i in 1:dim(data)[2]) {graphics::hist(data[,i], main=NULL, xlab=colnames(data)[i], ylab=NULL)} | ||
graphics::par(op)} | ||
} | ||
if(match.arg(type)=="impact"){ | ||
input <- stats::na.omit(data) | ||
table <- as.data.frame(matrix(rep(NA, 2*dim(data)[2]), dim(data)[2], 2)) | ||
for(j in 1:dim(data)[2]) { | ||
if(binary.data==FALSE) { | ||
if(match.arg(split)=="median"){ | ||
hi <- input[input[,j]> stats::median(input[,j]),][,-j] | ||
lo <- input[input[,j] < stats::median(input[,j]),][,-j] | ||
} | ||
if(match.arg(split)=="mean"){ | ||
hi <- input[input[,j]> mean(input[,j]),][,-j] | ||
lo <- input[input[,j] < mean(input[,j]),][,-j] | ||
} | ||
if(match.arg(split)=="forceEqual"){ | ||
hi <- input[input[,j] > stats::median(input[,j]),] | ||
lo <- input[input[,j] < stats::median(input[,j]),] | ||
med <- input[input[,j] == stats::median(input[,j]),] | ||
random_sample_med <- med[sample(1:dim(med)[1], abs(dim(hi)[1]-dim(lo)[1])),] | ||
if(dim(hi)[1]<dim(lo)[1]){hi <- rbind(hi, random_sample_med)} | ||
if(dim(hi)[1]>dim(lo)[1]){lo <- rbind(lo, random_sample_med)} | ||
hi <- hi[,-j] | ||
lo <- lo[,-j] | ||
} | ||
if(match.arg(split)=="cutEqual"){ | ||
hi <- input[input[,j] > stats::median(input[,j]),] | ||
lo <- input[input[,j] < stats::median(input[,j]),] | ||
if(dim(hi)[1]<dim(lo)[1]){lo <- lo[-sample(1:dim(lo)[1], abs(dim(hi)[1]-dim(lo)[1])),-j]} | ||
if(dim(hi)[1]>dim(lo)[1]){hi <- hi[-sample(1:dim(hi)[1], abs(dim(hi)[1]-dim(lo)[1])),-j]} | ||
} | ||
if(match.arg(split)=="quartile"){ | ||
hi <- input[input[,j]>= stats::quantile(input[,j],probs=.75),][,-j] | ||
lo <- input[input[,j]<= stats::quantile(input[,j],probs=.25),][,-j] | ||
} | ||
} | ||
if(binary.data==TRUE) { | ||
hi <- input[input[,j]==1,][,-j] | ||
lo <- input[input[,j]==0,][,-j] | ||
if(match.arg(split)=="cutEqual"){ | ||
if(dim(hi)[1]<dim(lo)[1]){lo <- lo[-sample(1:dim(lo)[1], abs(dim(hi)[1]-dim(lo)[1])),]} | ||
if(dim(hi)[1]>dim(lo)[1]){hi <- hi[-sample(1:dim(hi)[1], abs(dim(hi)[1]-dim(lo)[1])),]} | ||
} | ||
} | ||
table[j,1] <- sum(diag(stats::var(lo))) | ||
table[j,2] <- sum(diag(stats::var(hi))) | ||
if(abs((table[j,1]/table[j,2])-1)>(percent/100)) {message("Equal network variances violation: difference in variance between halves on node \"", | ||
colnames(data)[j], "\" is greater than ", percent)} | ||
} | ||
colnames(table) <- c("Low Half (variance)", "High Half (variance)") | ||
rownames(table) <- colnames(data) | ||
cat("Total network variances \n") | ||
table | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.