├── .Rbuildignore
├── .github
└── ISSUE_TEMPLATE
│ ├── bug-report.md
│ └── feature-request.md
├── DESCRIPTION
├── LICENSE
├── NAMESPACE
├── NEWS
├── R
├── ECO.R
├── ECOplusMaST.R
├── LoGo.R
├── MFCF.R
├── MaST.R
├── NetworkToolbox.R
├── TMFG.R
├── adapt.a.R
├── behavOpen.R
├── betweenness.R
├── binarize.R
├── closeness.R
├── clustcoeff.R
├── comcat.R
├── comm.close.R
├── comm.eigen.R
├── comm.str.R
├── conn.R
├── convert2igraph.R
├── convertConnBrainMat.R
├── cor2cov.R
├── core.items.R
├── cpm.R
├── dCor.R
├── dCor.parallel.R
├── degree.R
├── depend.R
├── depna.R
├── desc.R
├── desc.all.R
├── distance.R
├── diversity.R
├── edgerep.R
├── eigenvector.R
├── flow.frac.R
├── gain.functions.R
├── gateway.R
├── hybrid.R
├── impact.R
├── is.graphical.R
├── kld.R
├── lattnet.R
├── leverage.R
├── louvain.R
├── methods.R
├── neoOpen.R
├── net.coverage.R
├── network.coverage.R
├── network.permutation.R
├── neuralnetfilter.R
├── openness.R
├── participation.R
├── pathlengths.R
├── plot.cpm.R
├── randnet.R
├── reg.R
├── resp.rep.R
├── rmse.R
├── rspbc.R
├── sim.chordal.R
├── sim.swn.R
├── smallworldness.R
├── stable.R
├── strength.R
├── threshold.R
├── transitivity.R
├── un.direct.R
├── utils-NetworkToolbox.R
└── zzz.R
├── README.md
├── data
├── behavOpen.RData
├── neoOpen.rda
├── openness.RData
└── openness.key.RData
├── inst
└── CITATION
└── man
├── ECO.Rd
├── ECOplusMaST.Rd
├── LoGo.Rd
├── MFCF.Rd
├── MaST.Rd
├── NetworkToolbox-package.Rd
├── TMFG.Rd
├── adapt.a.Rd
├── behavOpen.Rd
├── betweenness.Rd
├── binarize.Rd
├── closeness.Rd
├── clustcoeff.Rd
├── comcat.Rd
├── comm.close.Rd
├── comm.eigen.Rd
├── comm.str.Rd
├── conn.Rd
├── convert2igraph.Rd
├── convertConnBrainMat.Rd
├── cor2cov.Rd
├── core.items.Rd
├── cpm.Rd
├── dCor.Rd
├── dCor.parallel.Rd
├── degree.Rd
├── depend.Rd
├── depna.Rd
├── desc.Rd
├── desc.all.Rd
├── distance.Rd
├── diversity.Rd
├── edgerep.Rd
├── eigenvector.Rd
├── flow.frac.Rd
├── gain.functions.Rd
├── gateway.Rd
├── hybrid.Rd
├── impact.Rd
├── is.graphical.Rd
├── kld.Rd
├── lattnet.Rd
├── leverage.Rd
├── louvain.Rd
├── neoOpen.Rd
├── net.coverage.Rd
├── network.coverage.Rd
├── network.permutation.Rd
├── neuralnetfilter.Rd
├── openness.Rd
├── participation.Rd
├── pathlengths.Rd
├── plot.cpm.Rd
├── randnet.Rd
├── reg.Rd
├── resp.rep.Rd
├── rmse.Rd
├── rspbc.Rd
├── sim.chordal.Rd
├── sim.swn.Rd
├── smallworldness.Rd
├── stable.Rd
├── strength.Rd
├── threshold.Rd
├── transitivity.Rd
└── un.direct.Rd
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^\.dictionaries$
2 | ^\.git$
3 | ^\.github$
4 | ^\.Rproj\.user$
5 | ^Readme\.md$
6 | .gitignore
7 | LICENSE
8 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug Report
3 | about: What's gone wrong?
4 | title: Bugs and Errors
5 | labels: bug
6 | assignees: AlexChristensen
7 |
8 | ---
9 |
10 |
11 |
12 | **Summary**
13 | [A clear and concise description of what the error is.]
14 |
15 |
16 |
17 | **Reproduce**
18 | [Provide code, data, and examples to reproduce error.]
19 |
20 |
21 |
22 | **NetworkToolbox Version**
23 | NetworkToolbox [version number]
24 |
25 |
26 |
27 | **Computer Specifications**
28 | Operating system: [Windows, Mac, Linux]
29 |
30 |
31 |
32 | **Additional context**
33 | [Add any other context about the problem here.]
34 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature-request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature Request
3 | about: Is something missing?
4 | title: Feature Request
5 | labels: enhancement
6 | assignees: AlexChristensen
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: NetworkToolbox
2 | Title: Methods and Measures for Brain, Cognitive, and Psychometric Network Analysis
3 | Version: 1.4.4
4 | Date: 2025-05-08
5 | Authors@R: c(person("Alexander", "Christensen", email = "alexpaulchristensen@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9798-7037")), person("Guido", "Previde Massara", role = c("ctb"), comment = c(ORCID = "0000-0003-0502-2789")))
6 | Maintainer: Alexander Christensen
7 | Description: Implements network analysis and graph theory measures used in neuroscience, cognitive science, and psychology. Methods include various filtering methods and approaches such as threshold, dependency (Kenett, Tumminello, Madi, Gur-Gershgoren, Mantegna, & Ben-Jacob, 2010 ), Information Filtering Networks (Barfuss, Massara, Di Matteo, & Aste, 2016 ), and Efficiency-Cost Optimization (Fallani, Latora, & Chavez, 2017 ). Brain methods include the recently developed Connectome Predictive Modeling (see references in package). Also implements several network measures including local network characteristics (e.g., centrality), community-level network characteristics (e.g., community centrality), global network characteristics (e.g., clustering coefficient), and various other measures associated with the reliability and reproducibility of network analysis.
8 | Depends: R (>= 3.6.0)
9 | License: GPL (>= 3.0)
10 | Encoding: UTF-8
11 | LazyData: true
12 | Imports: corrplot, doParallel, fdrtool, foreach, igraph, IsingFit, MASS, methods, parallel, pbapply, ppcor, psych, pwr, R.matlab, qgraph
13 | Suggests: googledrive
14 | RoxygenNote: 7.3.2
15 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | S3method(plot,cpm)
4 | export(ECO)
5 | export(ECOplusMaST)
6 | export(LoGo)
7 | export(MFCF)
8 | export(MaST)
9 | export(TMFG)
10 | export(adapt.a)
11 | export(betweenness)
12 | export(binarize)
13 | export(closeness)
14 | export(clustcoeff)
15 | export(comcat)
16 | export(comm.close)
17 | export(comm.eigen)
18 | export(comm.str)
19 | export(conn)
20 | export(convert2igraph)
21 | export(convertConnBrainMat)
22 | export(cor2cov)
23 | export(core.items)
24 | export(cpmEV)
25 | export(cpmFP)
26 | export(cpmFPperm)
27 | export(cpmIV)
28 | export(cpmIVperm)
29 | export(cpmPlot)
30 | export(dCor)
31 | export(dCor.parallel)
32 | export(degree)
33 | export(depend)
34 | export(depna)
35 | export(desc)
36 | export(desc.all)
37 | export(distance)
38 | export(diversity)
39 | export(edgerep)
40 | export(eigenvector)
41 | export(flow.frac)
42 | export(gateway)
43 | export(gfcnv_logdet)
44 | export(hybrid)
45 | export(impact)
46 | export(is.graphical)
47 | export(kld)
48 | export(lattnet)
49 | export(leverage)
50 | export(louvain)
51 | export(net.coverage)
52 | export(network.coverage)
53 | export(network.permutation)
54 | export(neuralnetfilter)
55 | export(participation)
56 | export(pathlengths)
57 | export(randnet)
58 | export(reg)
59 | export(resp.rep)
60 | export(rmse)
61 | export(rspbc)
62 | export(sim.chordal)
63 | export(sim.swn)
64 | export(smallworldness)
65 | export(stable)
66 | export(strength)
67 | export(threshold)
68 | export(transitivity)
69 | export(un.direct)
70 | importFrom(MASS,psi.bisquare)
71 | importFrom(foreach,"%dopar%")
72 | importFrom(grDevices,colorRampPalette)
73 | importFrom(grDevices,dev.new)
74 | importFrom(graphics,abline)
75 | importFrom(graphics,hist)
76 | importFrom(graphics,legend)
77 | importFrom(graphics,par)
78 | importFrom(graphics,plot)
79 | importFrom(graphics,text)
80 | importFrom(methods,is)
81 | importFrom(psych,corFiml)
82 | importFrom(stats,coef)
83 | importFrom(stats,complete.cases)
84 | importFrom(stats,cor)
85 | importFrom(stats,cor.test)
86 | importFrom(stats,cov)
87 | importFrom(stats,cov2cor)
88 | importFrom(stats,dist)
89 | importFrom(stats,glm)
90 | importFrom(stats,lm)
91 | importFrom(stats,lm.fit)
92 | importFrom(stats,na.action)
93 | importFrom(stats,na.omit)
94 | importFrom(stats,pchisq)
95 | importFrom(stats,pf)
96 | importFrom(stats,pt)
97 | importFrom(stats,qchisq)
98 | importFrom(stats,qf)
99 | importFrom(stats,qt)
100 | importFrom(stats,rnorm)
101 | importFrom(stats,runif)
102 | importFrom(stats,sd)
103 | importFrom(stats,shapiro.test)
104 | importFrom(utils,capture.output)
105 | importFrom(utils,combn)
106 | importFrom(utils,packageDescription)
107 | importFrom(utils,setTxtProgressBar)
108 | importFrom(utils,txtProgressBar)
109 |
--------------------------------------------------------------------------------
/R/ECO.R:
--------------------------------------------------------------------------------
1 | #' ECO Neural Network Filter
2 | #' @description Applies the ECO neural network filtering method
3 | #'
4 | #' @param data Can be a dataset or a correlation matrix
5 | #'
6 | #' @param directed Is the network directed?
7 | #' Defaults to \code{FALSE}.
8 | #' Set \code{TRUE} if the network is directed
9 | #'
10 | #' @return A sparse association matrix
11 | #'
12 | #' @examples
13 | #' eco.net <- ECO(neoOpen)
14 | #'
15 | #' @references
16 | #' Fallani, F. D. V., Latora, V., & Chavez, M. (2017).
17 | #' A topological criterion for filtering information in complex brain networks.
18 | #' \emph{PLoS Computational Biology}, \emph{13}, e1005305.
19 | #'
20 | #' @author Alexander Christensen
21 | #'
22 | #' @export
23 | #ECO Neural Network Filter----
24 | ECO <- function (data, directed = FALSE)
25 | {
26 | #corrlation matrix
27 | if(nrow(data)==ncol(data)){cormat<-data
28 | }else{cormat<-cor(data)}
29 |
30 | C<-cormat
31 |
32 | n<-ncol(C)
33 | S<-C
34 | if(directed)
35 | {
36 | numcon<-3*n
37 | ind<-which(C!=0)
38 | }else{C<-upper.tri(C,diag=TRUE)
39 | numcon<-1.5*n
40 | ind<-which(upper.tri(C,diag=TRUE)!=0)}
41 |
42 | S<-ifelse(C==1,S,0)
43 |
44 | if(numcon>length(ind))
45 | {
46 | stop("Input matrix is too sparse")
47 | }
48 |
49 | sorind<-matrix(0,nrow=length(ind),ncol=2)
50 |
51 | G<-S
52 | S<-abs(S)
53 |
54 | x<-S[ind]
55 | y<-ind
56 | h<-cbind(ind,S[ind])
57 | sorind<-h[order(-h[,2]),]
58 | C[sorind[(numcon+1):nrow(sorind),1]]<-0
59 |
60 | if(directed)
61 | {W<-C}else{W<-C+t(C)
62 | diag(W)<-1}
63 | J<-G+t(G)
64 | diag(J)<-1
65 | W<-ifelse(W!=0,J,0)
66 | W<-as.data.frame(W)
67 | colnames(W)<-colnames(data)
68 | row.names(W)<-colnames(data)
69 | W<-as.matrix(W)
70 | return(W)
71 | }
72 | #----
--------------------------------------------------------------------------------
/R/ECOplusMaST.R:
--------------------------------------------------------------------------------
1 | #' ECO+MaST Network Filter
2 | #' @description Applies the \code{\link[NetworkToolbox]{ECO}} neural network filtering method
3 | #' combined with the \code{\link[NetworkToolbox]{MaST}} filtering method
4 | #'
5 | #' @param data Can be a dataset or a correlation matrix
6 | #'
7 | #' @return A sparse association matrix
8 | #'
9 | #' @examples
10 | #' # half the variables for CRAN checks
11 | #' ECOplusMaST.net <- ECOplusMaST(neoOpen[,c(1:24)])
12 | #'
13 | #' @references
14 | #' Fallani, F. D. V., Latora, V., & Chavez, M. (2017).
15 | #' A topological criterion for filtering information in complex brain networks.
16 | #' \emph{PLoS Computational Biology}, \emph{13}, e1005305.
17 | #'
18 | #' @author Alexander Christensen
19 | #'
20 | #' @export
21 | #ECO Filter + MaST----
22 | ECOplusMaST <- function (data)
23 | {
24 | #corrlation matrix
25 | if(nrow(data)==ncol(data)){cormat<-data
26 | }else{cormat<-cor(data)}
27 |
28 | a<-MaST(data)
29 | b<-ECO(data)
30 | k<-matrix(NA,nrow=nrow(a),ncol=ncol(a))
31 | for(i in 1:nrow(a))
32 | for(j in 1:ncol(a))
33 | if(a[i,j]==b[i,j]){k[i,j]<-a[i,j]}else k[i,j]<-a[i,j]+b[i,j]
34 |
35 | k<-as.data.frame(k)
36 | colnames(k)<-colnames(data)
37 | row.names(k)<-colnames(data)
38 | k<-as.matrix(k)
39 | return(k)
40 | }
41 | #----
--------------------------------------------------------------------------------
/R/NetworkToolbox.R:
--------------------------------------------------------------------------------
1 | #' NetworkToolbox--package
2 | #' @description Implements network analysis and graph theory measures used
3 | #' in neuroscience, cognitive science, and psychology.
4 | #' Methods include various filtering methods and approaches such as
5 | #' threshold, dependency, Information Filtering Networks, and Efficiency-Cost Optimization.
6 | #' Brain methods include the recently developed Connectome Predictive Modeling.
7 | #' Also implements several network measures including local network characteristics
8 | #' (e.g., centrality), global network characteristics (e.g., clustering coefficient),
9 | #' and various other measures associated with the reliability and
10 | #' reproducibility of network analysis.
11 | #'
12 | #' @references
13 | #' Christensen, A. P. (in press).
14 | #' NetworkToolbox: Methods and measures for brain, cognitive, and psychometric network analysis in R.
15 | #' \emph{The R Journal}, \emph{10}, 422-439.
16 | #'
17 | #' @author Alexander Christensen
18 | #'
19 | #' @importFrom utils packageDescription
20 | #' @importFrom methods is
21 | #'
22 | "_PACKAGE"
23 | #> [1] "_PACKAGE"
24 | #NetworkToolbox----
--------------------------------------------------------------------------------
/R/behavOpen.R:
--------------------------------------------------------------------------------
1 | #NEO-PI-3 for Resting-state Data----
2 | #'NEO-PI-3 for Resting-state Data
3 | #'
4 | #' NEO-PI-3 Openness to Experience associated with resting-state data (\emph{n} = 144).
5 | #'
6 | #' Behavioral data of NEO-PI-3 associated with each connectivity matrix (open).
7 | #'
8 | #' To access the resting-state brain data, please go to \url{https://drive.google.com/file/d/1T7_mComB6HPxJxZZwwsLLSYHXsOuvOBt/view?usp=sharing}
9 | #'
10 | #'
11 | #'
12 | #'
13 | #' @name behavOpen
14 | #'
15 | #' @docType data
16 | #'
17 | #' @usage data(behavOpen)
18 | #'
19 | #' @format behavOpen (vector, length = 144)
20 | #'
21 | #' @keywords datasets
22 | #'
23 | #' @references
24 | #' Beaty, R. E., Chen, Q., Christensen, A. P., Qiu, J., Silvia, P. J., & Schacter, D. L. (2018).
25 | #' Brain networks of the imaginative mind: Dynamic functional connectivity of default and cognitive control networks relates to Openness to Experience.
26 | #' \emph{Human Brain Mapping}, \emph{39}, 811-821.
27 | #'
28 | #' Beaty, R. E., Kenett, Y. N., Christensen, A. P., Rosenberg, M. D., Benedek, M., Chen, Q., ... & Silvia, P. J. (2018).
29 | #' Robust prediction of individual creative ability from brain functional connectivity.
30 | #' \emph{Proceedings of the National Academy of Sciences}, 201713532.
31 | #'
32 | #' @examples
33 | #' data("behavOpen")
34 | NULL
35 | #----
--------------------------------------------------------------------------------
/R/binarize.R:
--------------------------------------------------------------------------------
1 | #' Binarize Network
2 | #' @description Converts weighted adjacency matrix to a binarized adjacency matrix
3 | #'
4 | #' @param A An adjacency matrix of network data (or an array of matrices)
5 | #'
6 | #' @return Returns an adjacency matrix of 1's and 0's
7 | #'
8 | #' @examples
9 | #' # Pearson's correlation only for CRAN checks
10 | #' A <- TMFG(neoOpen, normal = FALSE)$A
11 | #'
12 | #' neoB <- binarize(A)
13 | #'
14 | #' @author Alexander Christensen
15 | #'
16 | #' @export
17 | #Binarize function----
18 | binarize <- function (A)
19 | {
20 | A <- as.matrix(A)
21 | bin <- ifelse(A!=0,1,0)
22 | row.names(bin) <- row.names(A)
23 | colnames(bin) <- colnames(A)
24 |
25 | return(bin)
26 | }
27 | #----
--------------------------------------------------------------------------------
/R/closeness.R:
--------------------------------------------------------------------------------
1 | #' Closeness Centrality
2 | #' @description Computes closeness centrality of each node in a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param weighted Is the network weighted?
7 | #' Defaults to \code{TRUE}.
8 | #' Set to \code{FALSE} for unweighted measure of closeness centrality
9 | #'
10 | #' @return A vector of closeness centrality values for each node in the network
11 | #'
12 | #' @examples
13 | #' # Pearson's correlation only for CRAN checks
14 | #' A <- TMFG(neoOpen, normal = FALSE)$A
15 | #'
16 | #' #Weighted LC
17 | #' LC <- closeness(A)
18 | #'
19 | #' #Unweighted LC
20 | #' LC <- closeness(A, weighted = FALSE)
21 | #'
22 | #' @references
23 | #' Rubinov, M., & Sporns, O. (2010).
24 | #' Complex network measures of brain connectivity: Uses and interpretations.
25 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
26 | #'
27 | #' @author Alexander Christensen
28 | #'
29 | #' @export
30 | #Closeness Centrality----
31 | closeness <- function (A, weighted = TRUE)
32 | {
33 | if(nrow(A)!=ncol(A))
34 | {stop("Input not an adjacency matrix")}
35 |
36 | A <- abs(A)
37 | A <- as.matrix(A)
38 |
39 | if (!weighted)
40 | {D<-distance(A,weighted=FALSE)
41 | }else if(weighted)
42 | {D<-distance(A,weighted=TRUE)}
43 |
44 | C <- vector("numeric", length = ncol(D))
45 |
46 | for(i in 1:ncol(D))
47 | {C[i]<-1/sum(D[,i])}
48 |
49 | LC<-C*100
50 |
51 | LC<-round(LC,3)
52 |
53 | names(LC) <- colnames(A)
54 |
55 | return(LC)
56 | }
57 | #----
--------------------------------------------------------------------------------
/R/clustcoeff.R:
--------------------------------------------------------------------------------
1 | #' Clustering Coefficient
2 | #' @description Computes global clustering coefficient (CC) and local clustering coefficient (CCi)
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param weighted Is the network weighted?
7 | #' Defaults to \code{FALSE}.
8 | #' Set to \code{TRUE} for weighted measures of CC and CCi
9 | #' @return Returns a list containing:
10 | #'
11 | #' \item{CC}{Global clustering coefficient. The average clustering coefficient for each node in the network}
12 | #'
13 | #' \item{CCi}{Local clustering coefficient. The clustering coefficient for each node in the network}
14 | #'
15 | #' @examples
16 | #' # Pearson's correlation only for CRAN checks
17 | #' A <- TMFG(neoOpen, normal = FALSE)$A
18 | #'
19 | #' #Unweighted CC
20 | #' CCu <- clustcoeff(A)
21 | #'
22 | #' #Weighted CC
23 | #' CCw <- clustcoeff(A, weighted=TRUE)
24 | #'
25 | #' @references
26 | #' Rubinov, M., & Sporns, O. (2010).
27 | #' Complex network measures of brain connectivity: Uses and interpretations.
28 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
29 | #'
30 | #' @author Alexander Christensen
31 | #'
32 | #' @export
33 | #Clustering Coefficient----
34 | clustcoeff <- function (A, weighted = FALSE)
35 | {
36 | diag(A) <- 0
37 |
38 | if(nrow(A)!=ncol(A))
39 | {stop("Input not an adjacency matrix")}
40 | if(!weighted)
41 | {n<-ncol(A)
42 | A<-ifelse(A!=0,1,0)
43 | C<-matrix(0,nrow=n,ncol=1)
44 |
45 | for(i in 1:n)
46 | {
47 | v<-which(A[i,]!=0)
48 | k<-length(v)
49 | if(k >= 2)
50 | {
51 | S<-A[v,v]
52 | C[i]<-sum(S)/(k^2-k)
53 | }}
54 |
55 | C <- round(as.vector(C),3)
56 | names(C)<-colnames(A)
57 |
58 | CCi<-C
59 | CC <- mean(C)
60 |
61 | }else{
62 | K<-colSums(A!=0)
63 | m<-A^(1/3)
64 | cyc<-diag(m%*%m%*%m)
65 | K[cyc==0]<-Inf
66 | C <- as.vector(round(cyc/(K*(K-1)),3))
67 | names(C)<-colnames(A)
68 | CCi<-C
69 | CC<-mean(C)
70 | }
71 |
72 | return(list(CC=CC,CCi=CCi))
73 | }
74 | #----
--------------------------------------------------------------------------------
/R/comm.close.R:
--------------------------------------------------------------------------------
1 | #' Community Closeness Centrality
2 | #' @description Computes the community closeness centrality measure of each
3 | #' community in a network
4 | #'
5 | #' @param A An adjacency matrix of network data
6 | #'
7 | #' @param comm A vector or matrix corresponding to the
8 | #' community each node belongs to
9 | #'
10 | #' @param weighted Is the network weighted?
11 | #' Defaults to \code{FALSE}.
12 | #' Set to \code{TRUE} for weighted measures
13 | #'
14 | #' @return A vector of community closeness centrality values for each specified
15 | #' community in the network
16 | #' (larger values suggest more central positioning)
17 | #'
18 | #' @examples
19 | #' # Pearson's correlation only for CRAN checks
20 | #' A <- TMFG(neoOpen, normal = FALSE)$A
21 | #'
22 | #' comm <- igraph::walktrap.community(convert2igraph(abs(A)))$membership
23 | #'
24 | #' #Weighted
25 | #' result <- comm.close(A, comm)
26 | #'
27 | #' #Unweighted
28 | #' result <- comm.close(A, comm, weighted = FALSE)
29 | #'
30 | #' @references
31 | #' Christensen, A. P. (in press).
32 | #' NetworkToolbox: Methods and measures for brain, cognitive, and psychometric network analysis in R.
33 | #' \emph{The R Journal}, \emph{10}, 422-439.
34 | #'
35 | #' @author Alexander Christensen
36 | #'
37 | #' @export
38 | #Community Closeness Centrality----
39 | comm.close <- function (A, comm, weighted = FALSE)
40 | {
41 | if(is.null(comm))
42 | {stop("comm must be input")}
43 |
44 | comm <- as.vector(comm)
45 |
46 | if(ncol(A)!=length(comm))
47 | {stop("length of comm does not match nodes in matrix")}
48 |
49 | uniq <- unique(comm)
50 | uniq <- uniq[order(uniq)]
51 | len <- length(uniq)
52 |
53 | allP <- pathlengths(A, weighted = weighted)$ASPLi
54 | mean.allP <- mean(allP)
55 | remove <- vector("numeric",length=len)
56 |
57 | for(j in 1:len)
58 | {
59 | rem <- which(comm==uniq[j])
60 |
61 | remove[j] <- 1/mean(allP[rem])
62 | }
63 |
64 | names(remove) <- uniq
65 |
66 | return(remove)
67 | }
68 | #----
--------------------------------------------------------------------------------
/R/comm.eigen.R:
--------------------------------------------------------------------------------
1 | #' Community Eigenvector Centrality
2 | #' @description Computes the \link[NetworkToolbox]{flow.frac} for each
3 | #' community in the network. The values are equivalent to the community's
4 | #' eigenvector centrality
5 | #'
6 | #' @param A An adjacency matrix
7 | #'
8 | #' @param comm A vector or matrix corresponding to the
9 | #' community each node belongs to
10 | #'
11 | #' @param weighted Is the network weighted?
12 | #' Defaults to \code{TRUE}.
13 | #' Set to \code{FALSE} for weighted measures
14 | #'
15 | #' @return A vector of community eigenvector centrality values for
16 | #' each specified community in the network
17 | #' (larger values suggest more central positioning)
18 | #'
19 | #' @examples
20 | #' # Pearson's correlation only for CRAN checks
21 | #' A <- TMFG(neoOpen, normal = FALSE)$A
22 | #'
23 | #' comm <- igraph::walktrap.community(convert2igraph(abs(A)))$membership
24 | #'
25 | #' result <- comm.eigen(A, comm)
26 | #'
27 | #' @references
28 | #' Giscard, P. L., & Wilson, R. C. (2018).
29 | #' A centrality measure for cycles and subgraphs II.
30 | #' \emph{Applied Network Science}, \emph{3}, 9.
31 | #'
32 | #' @author Alexander Christensen
33 | #'
34 | #' @export
35 | #Community EC
36 | comm.eigen <- function (A, comm, weighted = TRUE)
37 | {
38 | if(is.null(comm))
39 | {stop("comm must be input")}
40 |
41 | comm <- as.vector(comm)
42 |
43 | if(ncol(A)!=length(comm))
44 | {stop("length of comm does not match nodes in matrix")}
45 |
46 | uniq <- unique(comm)
47 | uniq <- uniq[order(uniq)]
48 | len <- length(uniq)
49 |
50 | commEC <- vector("numeric",length=len)
51 |
52 | if(!weighted)
53 | {A <- binarize(A)}
54 |
55 | for(i in 1:len)
56 | {commEC[i] <- flow.frac(A, which(comm==uniq[i]))}
57 |
58 | names(commEC) <- uniq
59 |
60 | return(commEC)
61 | }
62 | #----
--------------------------------------------------------------------------------
/R/comm.str.R:
--------------------------------------------------------------------------------
1 | #' Community Strength/Degree Centrality
2 | #' @description Computes the community
3 | #' \code{\link[NetworkToolbox]{strength}}/\code{\link[NetworkToolbox]{degree}}
4 | #' centrality measure of each community in a network or computes the
5 | #' \code{\link[NetworkToolbox]{strength}}/\code{\link[NetworkToolbox]{degree}}
6 | #' centrality measure of each community's connections to the other communities
7 | #'
8 | #' @param A An adjacency matrix of network data
9 | #'
10 | #' @param comm A vector corresponding to the
11 | #' community each node belongs to
12 | #'
13 | #' @param weighted Is the network weighted?
14 | #' Defaults to \code{TRUE}.
15 | #' Set to \code{FALSE} for weighted measures
16 | #'
17 | #' @param measure Type of measure to compute:
18 | #'
19 | #' \itemize{
20 | #'
21 | #' \item \code{"within"} --- Computes the community strength or degree of nodes within its own community
22 | #'
23 | #' \item \code{"between"} --- Computes the community strength or degree of nodes outside of its own community
24 | #'
25 | #' }
26 | #'
27 | #' @return A vector of community strength/degree centrality values for each specified
28 | #' community in the network
29 | #' (larger values suggest more central positioning)
30 | #'
31 | #' @examples
32 | #' # Pearson's correlation only for CRAN checks
33 | #' A <- TMFG(neoOpen, normal = FALSE)$A
34 | #'
35 | #' comm <- igraph::walktrap.community(convert2igraph(abs(A)))$membership
36 | #'
37 | #' #Strength
38 | #' within.ns <- comm.str(A, comm, measure = "within")
39 | #' between.ns <- comm.str(A, comm, measure = "between")
40 | #'
41 | #' #Degree
42 | #' within.deg <- comm.str(A, comm, weighted = FALSE, measure = "within")
43 | #' between.deg <- comm.str(A, comm, weighted = FALSE, measure = "between")
44 | #'
45 | #' @author Alexander Christensen
46 | #'
47 | #' @export
48 | #Community Strength/Degree Centrality
49 | # Updated 26.11.2022
50 | comm.str <- function (A, comm, weighted = TRUE,
51 | measure = c("within","between"))
52 | {
53 | if(is.null(comm))
54 | {stop("comm must be input")}
55 |
56 | if(missing(measure))
57 | {measure <- "between"
58 | }else{measure <- match.arg(measure)}
59 |
60 | comm <- as.vector(comm)
61 |
62 | if(ncol(A)!=length(comm))
63 | {stop("length of comm does not match nodes in matrix")}
64 |
65 | uniq <- unique(comm)
66 | len <- length(uniq)
67 |
68 | remove <- matrix(0,nrow=len,ncol=1)
69 |
70 | for(j in 1:len)
71 | {
72 | rem <- which(comm==uniq[j])
73 |
74 | if(length(rem)!=1)
75 | {
76 | if(measure == "within")
77 | {
78 | if(weighted)
79 | {remove[j,] <- sum(colSums(A[rem,rem]))
80 | }else{remove[j,] <- sum(colSums(binarize(A)[rem,rem]))}
81 | }else if(measure == "between")
82 | {
83 | if(weighted)
84 | {remove[j,] <- sum(colSums(A[-rem,rem]))
85 | }else{remove[j,] <- sum(colSums(binarize(A)[-rem,rem]))}
86 | }
87 |
88 |
89 | }else{remove[j,] <- 0}
90 | }
91 |
92 | norm <- as.vector(round(remove,3))
93 |
94 | names(norm) <- uniq
95 |
96 | res <- norm[sort(names(norm))]
97 |
98 | return(res)
99 | }
100 | #----
--------------------------------------------------------------------------------
/R/conn.R:
--------------------------------------------------------------------------------
1 | #' Network Connectivity
2 | #' @description Computes the average and standard deviation of the weights in the network
3 | #'
4 | #' @param A An adjacency matrix of a network
5 | #'
6 | #' @return Returns a list containing:
7 | #'
8 | #' \item{weights}{Each edge weight in the network}
9 | #'
10 | #' \item{mean}{The mean of the edge weights in the network}
11 | #'
12 | #' \item{sd}{The standard deviation of the edge weights in the network}
13 | #'
14 | #' \item{total}{The sum total of the edge weights in the network}
15 | #'
16 | #' @examples
17 | #' # Pearson's correlation only for CRAN checks
18 | #' A <- TMFG(neoOpen, normal = FALSE)$A
19 | #'
20 | #' connectivity <- conn(A)
21 | #'
22 | #' @author Alexander Christensen
23 | #'
24 | #' @export
25 | #Network Connectivity----
26 | conn <- function (A)
27 | {
28 | diag(A)<-0
29 |
30 | weights<-0
31 | wc<-0
32 | B<-A[lower.tri(A)]
33 | for(i in 1:length(B))
34 | if (B[i]!=0)
35 | {
36 | wc <- wc+1
37 | weights[wc] <- B[i]
38 | }
39 | tot<-sum(weights)
40 | mea<-mean(weights)
41 | s<-sd(weights)
42 |
43 | possible<-sum(ifelse(A!=0,1,0)/2)
44 | den<-possible/((ncol(A)^2-ncol(A))/2)
45 |
46 | return(list(weights=weights,mean=mea,sd=s,total=tot,density=den))
47 | }
48 | #----
--------------------------------------------------------------------------------
/R/convert2igraph.R:
--------------------------------------------------------------------------------
1 | #' Convert Network(s) to igraph's Format
2 | #' @description Converts single or multiple networks into \code{igraph}'s format for network analysis
3 | #'
4 | #' @param A Adjacency matrix (network matrix) or brain connectivity array
5 | #' (from \code{\link[NetworkToolbox]{convertConnBrainMat}})
6 | #'
7 | #' @param neural Is input a brain connectivity array (i.e., m x m x n)?
8 | #' Defaults to \code{FALSE}.
9 | #' Set to \code{TRUE} to convert each brain connectivity matrix
10 | #'
11 | #' @return Returns a network matrix in \code{igraph}'s format or
12 | #' returns a list of brain connectivity matrices each of which have been
13 | #' convert to \code{igraph}'s format
14 | #'
15 | #' @examples
16 | #' # Pearson's correlation only for CRAN checks
17 | #' A <- TMFG(neoOpen, normal = FALSE)$A
18 | #'
19 | #' igraphNetwork <- convert2igraph(A)
20 | #'
21 | #' \dontrun{
22 | #' neuralarray <- convertConnBrainMat()
23 | #'
24 | #' igraphNeuralList <- convert2igraph(neuralarray, neural = TRUE)
25 | #' }
26 | #'
27 | #' @author Alexander Christensen
28 | #'
29 | #' @export
30 | #Convert matrices to igraph format----
31 | convert2igraph <- function (A, neural = FALSE)
32 | {
33 | if(!neural)
34 | {
35 | net <- igraph::as.igraph(qgraph::qgraph(A,DoNotPlot=TRUE))
36 | return(net)
37 | }else if(neural)
38 | {
39 | netlist <- list()
40 |
41 | n<-length(A)/nrow(A)/ncol(A)
42 |
43 | pb <- txtProgressBar(max=n, style = 3)
44 |
45 | for(i in 1:n)
46 | {
47 | netlist[[i]] <- igraph::as.igraph(qgraph::qgraph(A[,,i],DoNotPlot=TRUE))
48 | setTxtProgressBar(pb, i)
49 | }
50 | close(pb)
51 |
52 | return(netlist)
53 | }
54 | }
55 | #----
--------------------------------------------------------------------------------
/R/convertConnBrainMat.R:
--------------------------------------------------------------------------------
1 | #' Import CONN Toolbox Brain Matrices to R format
2 | #'
3 | #' @description Converts a Matlab brain z-score connectivity array (n x n x m)
4 | #' where \strong{n} is the n x n connectivity matrices and \strong{m} is the participant.
5 | #' If you would like to simply import a connectivity array from Matlab, then see the examples
6 | #'
7 | #' @param MatlabData Input for Matlab data file.
8 | #' Defaults to interactive file choice
9 | #'
10 | #' @param progBar Should progress bar be displayed?
11 | #' Defaults to \code{TRUE}.
12 | #' Set \code{FALSE} for no progress bar
13 | #'
14 | #' @return Returns a list containing:
15 | #'
16 | #' \item{rmat}{Correlation matrices for each participant (m) in an array (n x n x m)}
17 | #'
18 | #' \item{zmat}{Z-score matrices for each participant (m) in an array (n x n x m)}
19 | #'
20 | #' @examples
21 | #' \dontrun{
22 | #' neuralarray <- convertConnBrainMat()
23 | #'
24 | #' #Import correlation connectivity array from Matlab
25 | #' library(R.matlab)
26 | #' neuralarray<-readMat(file.choose())
27 | #' }
28 | #'
29 | #' @author Alexander Christensen
30 | #'
31 | #' @export
32 | #Convert CONN Toolbox Brain Matrices----
33 | #Updated 07.03.2020
34 | convertConnBrainMat <- function (MatlabData, progBar = TRUE)
35 | {
36 | ###########################
37 | #### MISSING ARGUMENTS ####
38 | ###########################
39 |
40 | if(missing(MatlabData))
41 | {mat <- R.matlab::readMat(file.choose())
42 | }else{mat <- R.matlab::readMat(MatlabData)}
43 |
44 | #######################
45 | #### MAIN FUNCTION ####
46 | #######################
47 |
48 | # If data imported is not in a list, then return
49 | if(!is.list(mat))
50 | {return(mat)
51 | }else{ # If data is in a list
52 |
53 | # Determine structure of data
54 | if("data" %in% names(mat)) # Time series data
55 | {
56 | # Grab data
57 | dat <- unlist(mat$data, recursive = FALSE)
58 |
59 | # Grab names
60 | dat.names <- unlist(mat$names)
61 |
62 | # Get names of ROIs
63 | names(dat) <- dat.names
64 |
65 | # Check for CSF, grey and white matter
66 | if(any(c("Grey Matter", "White Matter", "CSF") %in% names(dat)))
67 | {dat <- dat[-which(names(dat) == c("Grey Matter", "White Matter", "CSF"))]}
68 |
69 | return(dat)
70 |
71 | }else if("Z" %in% names(mat)) # Average time series data
72 | {
73 | #read in matlab data
74 | n1<-nrow(mat$Z) #determine number of rows
75 | n2<-ncol(mat$Z) #determine number of columns
76 | if(nrow(mat$Z)!=ncol(mat$Z))
77 | {warning("Row length does not match column length")}
78 | m<-length(mat$Z)/n1/n2 #determine number of participants
79 |
80 | #change row and column names
81 | coln1<-matrix(0,nrow=n1) #get row names
82 | for(i in 1:n1)
83 | {coln1[i,]<-mat$names[[i]][[1]][1,1]}
84 |
85 | coln2<-matrix(0,nrow=n2) #get column names
86 | for(i in 1:n2)
87 | {coln2[i,]<-mat$names2[[i]][[1]][1,1]}
88 |
89 | dat<-mat$Z
90 | if(progBar)
91 | {pb <- txtProgressBar(max=m, style = 3)}
92 |
93 | for(i in 1:m) #populate array
94 | {
95 | dat[,,i]<-psych::fisherz2r(mat$Z[,,i])
96 | for(j in 1:n1)
97 | for(k in 1:n2)
98 | if(is.na(dat[j,k,i]))
99 | {dat[j,k,i]<-0}
100 | if(progBar){setTxtProgressBar(pb, i)}
101 | }
102 | if(progBar){close(pb)}
103 |
104 | colnames(dat)<-coln2
105 | row.names(dat)<-coln1
106 |
107 | return(list(rmat=dat,zmat=mat$Z))
108 | }
109 |
110 | }
111 | }
112 | #----
--------------------------------------------------------------------------------
/R/cor2cov.R:
--------------------------------------------------------------------------------
1 | #' Convert Correlation Matrix to Covariance Matrix
2 | #' @description Converts a correlation matrix to a covariance matrix
3 | #'
4 | #' @param cormat A correlation matrix
5 | #'
6 | #' @param data The dataset the correlation matrix is from
7 | #'
8 | #' @return Returns a covariance matrix
9 | #'
10 | #' @examples
11 | #' cormat <- cor(neoOpen)
12 | #'
13 | #' covmat <- cor2cov(cormat,neoOpen)
14 | #'
15 | #' @author Alexander Christensen
16 | #'
17 | #' @export
18 | #Corrlation to covariance----
19 | cor2cov <- function (cormat, data)
20 | {
21 | sds<-apply(data,2,sd)
22 |
23 | b<-sds%*%t(sds)
24 |
25 | S<-cormat*b
26 |
27 | return(S)
28 | }
29 | #----
--------------------------------------------------------------------------------
/R/core.items.R:
--------------------------------------------------------------------------------
1 | #' Core Items
2 | #' @description Automatically determines core, intermediary, and peripheral items in the network.
3 | #' The entire network or within-community gradations can be determined. Based on the
4 | #' \code{\link[NetworkToolbox]{hybrid}} centrality
5 | #'
6 | #' @param A An adjacency matrix of network data
7 | #'
8 | #' @param comm A vector or matrix corresponding to the community each node belongs to
9 | #'
10 | #' @param by Should the core items be defined by network or communities?
11 | #' Defaults to \code{"network"}.
12 | #' Set to \code{"communities"} to define core items within communities
13 | #'
14 | #' @return Returns a list containing:
15 | #'
16 | #' \item{core}{Core items for each community}
17 | #'
18 | #' \item{inter}{Intermediate items for each community}
19 | #'
20 | #' \item{peri}{Peripheral items for each community}
21 | #'
22 | #' @examples
23 | #' #network
24 | #' # Pearson's correlation only for CRAN checks
25 | #' A <- TMFG(neoOpen, normal = FALSE)$A
26 | #'
27 | #' #core items by network
28 | #' coreBYnetwork <- core.items(A, by = "network")
29 | #'
30 | #' #theoretical factors
31 | #' comm <- c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
32 | #'
33 | #' #core items by communities
34 | #' coreBYcomm <- core.items(A, comm, by = "communities")
35 | #'
36 | #' @author Alexander Christensen
37 | #'
38 | #' @export
39 | #Core Items----
40 | core.items <- function (A, comm, by = c("network","communities"))
41 | {
42 | if(missing(comm))
43 | {by <- "network"
44 | }else{comm <- comm}
45 |
46 | if(missing(by))
47 | {by <- "communities"
48 | }else{by <- match.arg(by)}
49 |
50 | gradlist <- list()
51 |
52 | hc <- hybrid(A, BC = "random")
53 |
54 | left <- length(hc)
55 |
56 | name <- names(hc)
57 |
58 | if(by == "network")
59 | {
60 | dat <- hc
61 |
62 | corenum <- floor(left/3)
63 |
64 | cst <- 1:corenum
65 |
66 | left <- left - corenum
67 |
68 | internum <- floor(left/2)
69 |
70 | ist <- (corenum+1):(corenum+internum)
71 |
72 | left <- left - internum
73 |
74 | perinum <- left
75 |
76 | pst <- (corenum+internum+1):(corenum+internum+perinum)
77 |
78 | ord <- dat[order(dat,decreasing=TRUE)]
79 |
80 | gradlist$core <- ord[cst]
81 | gradlist$inter <- ord[ist]
82 | gradlist$peri <- ord[pst]
83 | }else if(by == "communities")
84 | {
85 | uniq <- unique(comm)
86 | if(is.numeric(uniq))
87 | {uniq <- as.character(uniq)}
88 |
89 | len <- length(uniq)
90 |
91 | for(i in 1:len)
92 | {
93 | left <- length(which(uniq[i]==comm))
94 |
95 | corenum <- floor(left/3)
96 |
97 | cst <- 1:corenum
98 |
99 | left <- left - corenum
100 |
101 | internum <- floor(left/2)
102 |
103 | ist <- (corenum+1):(corenum+internum)
104 |
105 | left <- left - internum
106 |
107 | perinum <- left
108 |
109 | pst <- (corenum+internum+1):(corenum+internum+perinum)
110 |
111 | items <- which(uniq[i]==comm)
112 |
113 | #core
114 | core <- hc[items][order(hc[items],decreasing = TRUE)][cst]
115 | gradlist[[uniq[i]]]$core <- core
116 |
117 | #inter
118 | inter <- hc[items][order(hc[items],decreasing = TRUE)][ist]
119 | gradlist[[uniq[i]]]$inter <- inter
120 |
121 | #peri
122 | peri <- hc[items][order(hc[items],decreasing = TRUE)][pst]
123 | gradlist[[uniq[i]]]$peri <- peri
124 | }
125 | }
126 |
127 | return(gradlist)
128 | }
129 | #----
--------------------------------------------------------------------------------
/R/dCor.parallel.R:
--------------------------------------------------------------------------------
1 | #' Parallelization of Distance Correlation for ROI Time Series
2 | #'
3 | #' @description Parallelizes the \code{\link[NetworkToolbox]{dCor}} function
4 | #' for faster computation times
5 | #'
6 | #' @param neurallist List of lists.
7 | #' A list containing the time series list from all participants imported from the
8 | #' \code{\link[NetworkToolbox]{convertConnBrainMat}} function
9 | #'
10 | #' @param cores Number of computer processing cores to use when performing covariate analyses.
11 | #' Defaults to \emph{n} - 1 total number of cores.
12 | #' Set to any number between 1 and maximum amount of cores on your computer
13 | #'
14 | #' @return Returns a \emph{m} x \emph{m} x \emph{n} array corresponding to distance correlations
15 | #' between ROIs (\emph{m} x \emph{m} matrix) for \emph{n} participants
16 | #'
17 | #' @examples
18 | #' \dontrun{
19 | #' # Import time series data
20 | #' for(i in 1:5)
21 | # {mat.list[[i]] <- convertConnBrainMat()}
22 | #'
23 | #' # Run distance correlation
24 | #' dCor.parallel(mat.list, cores = 2)
25 | #'
26 | #' }
27 | #'
28 | #' @references
29 | #' Yoo, K., Rosenberg, M. D., Noble, S., Scheinost, D., Constable, R. T., & Chun, M. M. (2019).
30 | #' Multivariate approaches improve the reliability and validity of functional connectivity and prediction of individual behaviors.
31 | #' \emph{NeuroImage}, \emph{197}, 212-223.
32 | #'
33 | #' @author Alexander Christensen
34 | #'
35 | #' @export
36 | #Parallelization of distance correlation----
37 | #Updated 03.05.2020
38 | dCor.parallel <- function(neurallist, cores)
39 | {
40 | ###########################
41 | #### MISSING ARGUMENTS ####
42 | ###########################
43 |
44 | if(missing(cores))
45 | {cores <- parallel::detectCores() - 1
46 | }else{cores <- cores}
47 |
48 | # Check data format
49 | if(!is.matrix(neurallist[[1]][[1]]))
50 | {
51 | neurallist <- lapply(neurallist, as.list)
52 | neurallist <- lapply(neurallist, function(x){lapply(x, as.matrix)})
53 | }
54 |
55 | #######################
56 | #### MAIN FUNCTION ####
57 | #######################
58 |
59 | # Initialize list
60 | dCor.list <- list()
61 |
62 | # Set up parallelization
63 | cl <- parallel::makeCluster(cores)
64 |
65 | # Export variables
66 | parallel::clusterExport(cl = cl,
67 | varlist = c("dCor.list"),
68 | envir = environment())
69 |
70 | # Compute distance correlation matrices
71 | dCor.list <- pbapply::pblapply(X = neurallist, cl = cl, FUN = NetworkToolbox::dCor)
72 |
73 | # Stop cluster
74 | parallel::stopCluster(cl)
75 |
76 | # Convert to array
77 | neuralarray <- simplify2array(dCor.list)
78 |
79 | # Change matrix names
80 | colnames(neuralarray) <- names(neurallist[[1]])
81 | row.names(neuralarray) <- colnames(neuralarray)
82 |
83 | return(neuralarray)
84 | }
85 | #----
--------------------------------------------------------------------------------
/R/degree.R:
--------------------------------------------------------------------------------
1 | #' Degree
2 | #' @description Computes degree of each node in a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @return A vector of degree values for each node in the network.
7 | #'
8 | #' If directed network, returns a list containing:
9 | #'
10 | #' \item{inDegree}{Degree of incoming edges (pointing to the node)}
11 | #'
12 | #' \item{outDegree}{Degree of outgoing edges (pointing away from the node)}
13 | #'
14 | #' \item{relInf}{Relative degree of incoming and outgoing edges.
15 | #' Positive values indicate more outgoing degree relative to incoming degree.
16 | #' Negative values indicate more incoming degree relative to outgoing degree}
17 | #'
18 | #' @examples
19 | #' #Undirected network
20 | #' ## Pearson's correlation only for CRAN checks
21 | #' A <- TMFG(neoOpen, normal = FALSE)$A
22 | #'
23 | #' deg <- degree(A)
24 | #'
25 | #' #Directed network
26 | #' \dontrun{
27 | #' dep <- depend(neoOpen)
28 | #'
29 | #' Adep <- TMFG(dep, depend = TRUE)$A
30 | #'
31 | #' deg <- degree(Adep)
32 | #' }
33 | #'
34 | #' @references
35 | #' Rubinov, M., & Sporns, O. (2010).
36 | #' Complex network measures of brain connectivity: Uses and interpretations.
37 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
38 | #'
39 | #' @author Alexander Christensen
40 | #'
41 | #' @export
42 | #Degree----
43 | # Updated 18.05.2020
44 | degree <- function (A)
45 | {
46 | if(nrow(A)!=ncol(A))
47 | {stop("Input not an adjacency matrix")}
48 |
49 | A <- as.matrix(A)
50 |
51 | A <- binarize(A)
52 |
53 | if(isSymmetric(A, check.attributes = FALSE))
54 | {
55 | Deg <- as.vector(colSums(A))
56 | names(Deg) <- colnames(A)
57 | return(Deg)
58 | }else
59 | {
60 | #In-degree
61 | inDeg <- as.vector(colSums(A, na.rm = TRUE))
62 | names(inDeg) <- colnames(A)
63 |
64 | #Out-degree
65 | outDeg <- as.vector(rowSums(A, na.rm = TRUE))
66 | names(outDeg) <- colnames(A)
67 |
68 | #Relative influence
69 | relinf <- as.vector((outDeg-inDeg)/(outDeg+inDeg))
70 | names(relinf) <- colnames(A)
71 |
72 | #Reciprocal degree
73 | for(i in 1:nrow(A))
74 | for(j in 1:ncol(A))
75 | {
76 | A[i,j] <- ifelse(A[i,j] == 1 & A[j,i] == 1, 1, 0)
77 | A[j,i] <- ifelse(A[i,j] == 1 & A[j,i] == 1, 1, 0)
78 | }
79 |
80 | recipDeg <- colSums(A, na.rm = TRUE)
81 | names(recipDeg) <- colnames(A)
82 |
83 | if(all(relinf<.001))
84 | {Deg <- as.vector(inDeg)
85 | names(Deg) <- colnames(A)
86 | return(Deg)
87 | }else{return(list(inDegree=inDeg,
88 | outDegree=outDeg,
89 | recipDegree=recipDeg,
90 | relInf=relinf))}
91 | }
92 | }
93 | #----
--------------------------------------------------------------------------------
/R/depna.R:
--------------------------------------------------------------------------------
1 | #' Dependency Neural Networks
2 | #' @description Applies the dependency network approach to neural network array
3 | #'
4 | #' @param neuralarray Array from \code{\link{convertConnBrainMat}} function
5 | #'
6 | #' @param cores Numeric.
7 | #' Number of cores to use in computing results.
8 | #' Set to \code{1} to not use parallel computing.
9 | #' Recommended to use maximum number of cores minus one
10 | #'
11 | #' @param ... Additional arguments from \code{\link{depend}} function
12 | #'
13 | #' @return Returns an array of n x n x m dependency matrices
14 | #'
15 | #' @examples
16 | #' \dontrun{
17 | #' neuralarray <- convertConnBrainMat()
18 | #'
19 | #' dependencyneuralarray <- depna(neuralarray)
20 | #' }
21 | #'
22 | #' @references
23 | #' Jacob, Y., Winetraub, Y., Raz, G., Ben-Simon, E., Okon-Singer, H., Rosenberg-Katz, K., ... & Ben-Jacob, E. (2016).
24 | #' Dependency Network Analysis (DEPNA) reveals context related influence of brain network nodes.
25 | #' \emph{Scientific Reports}, \emph{6}, 27444.
26 | #'
27 | #' Kenett, D. Y., Tumminello, M., Madi, A., Gur-Gershgoren, G., Mantegna, R. N., & Ben-Jacob, E. (2010).
28 | #' Dominating clasp of the financial sector revealed by partial correlation analysis of the stock market.
29 | #' \emph{PLoS one}, \emph{5}, e15032.
30 | #'
31 | #' @author Alexander Christensen
32 | #'
33 | #' @export
34 | #Dependency Network Analysis----
35 | # Updated 09.04.2020
36 | depna <- function (neuralarray, cores, ...)
37 | {
38 | # Convert to list for parallelization
39 | deplist <- list()
40 |
41 | # Loop through neuralarray
42 | for(i in 1:dim(neuralarray)[3])
43 | {deplist[[i]] <- neuralarray[,,i]}
44 |
45 | # Initialize depna array
46 | deparray <- neuralarray
47 |
48 | # Let user know data generation has started
49 | message("\nComputing dependency matrices...\n", appendLF = FALSE)
50 |
51 | # Parallel processing
52 | cl <- parallel::makeCluster(cores)
53 |
54 | # Export variables
55 | parallel::clusterExport(cl = cl,
56 | varlist = c("deplist"),
57 | envir=environment())
58 |
59 | # Compute dependency matrices
60 | depnalist <- pbapply::pblapply(X = deplist, cl = cl, FUN = depend,
61 | na.data = "pairwise", progBar = FALSE)
62 |
63 | # Stop cluster
64 | parallel::stopCluster(cl)
65 |
66 | # Convert back to array
67 | for(i in 1:length(depnalist))
68 | {deparray[,,i] <- depnalist[[i]]}
69 |
70 | return(deparray)
71 | }
72 | #----
--------------------------------------------------------------------------------
/R/desc.R:
--------------------------------------------------------------------------------
1 | #' Variable Descriptive Statistics
2 | #' @description Computes \code{mean}, standard deviation (\code{sd}), minimum value (\code{min}),
3 | #' maximum value (\code{max}),
4 | #' and univariate normal statistics (\code{normal?}) for a variable
5 | #'
6 | #' @param data A matrix or data frame
7 | #'
8 | #' @param column Column name or number in \code{data}
9 | #'
10 | #' @param histplot A histogram plot of the variable
11 | #'
12 | #' @return A data frame containing values for \code{n} (number of cases),
13 | #' \code{missing} (number of missing cases), \code{mean}, \code{sd}, \code{min}, and \code{max}. \code{normal?}
14 | #' will contain yes/no for whether the variable is normally distributed based
15 | #' on the \code{\link{shapiro.test}} for a variable
16 | #'
17 | #' @examples
18 | #'
19 | #' desc(neoOpen,1)
20 | #'
21 | #' @author Alexander Christensen
22 | #'
23 | #' @importFrom stats shapiro.test
24 | #'
25 | #' @export
26 | #Variable Descriptive Statistics----
27 | desc <- function(data, column, histplot = TRUE)
28 | {
29 | if(missing(column))
30 | {stop("Column name or number must be input")}
31 |
32 | if(is.character(column))
33 | {num <- which(colnames(data)==column)
34 | }else{num <- column}
35 |
36 | vec <- data[,num]
37 |
38 | len <- length(which(is.na(vec)))
39 |
40 | nas <- ifelse(len==0,0,len)
41 |
42 | desc.tab <- matrix(NA,nrow=1,ncol=7)
43 |
44 | desc.tab[1,1] <- length(vec) - nas
45 | desc.tab[1,2] <- nas
46 | desc.tab[1,3] <- round(mean(vec,na.rm=TRUE),3)
47 | desc.tab[1,4] <- round(sd(vec,na.rm=TRUE),3)
48 | desc.tab[1,c(5:6)] <- round(range(vec,na.rm=TRUE),3)
49 | desc.tab[1,7] <- ifelse(sd(vec,na.rm=TRUE)!=0,
50 | ifelse(shapiro.test(vec)$p.value<.05,"no","yes"),
51 | "uniform")
52 |
53 | desc.tab <- as.data.frame(desc.tab)
54 |
55 | colnames(desc.tab) <- c("n","missing","mean","sd","min","max","normal?")
56 | row.names(desc.tab) <- column
57 |
58 | if(histplot)
59 | {
60 | hist(vec, main = paste("Histogram of ",column,sep=""),
61 | xlab = paste(column),breaks=20)
62 | }
63 |
64 | return(desc.tab)
65 |
66 | }
67 | #----
--------------------------------------------------------------------------------
/R/desc.all.R:
--------------------------------------------------------------------------------
1 | #' Dataset Descriptive Statistics
2 | #' @description Computes \code{mean}, standard deviation (\code{sd}), minimum value (\code{min}),
3 | #' maximum value (\code{max}),
4 | #' and univariate normal statistics (\code{normal?}) for the entire dataset
5 | #'
6 | #' @param data A matrix or data frame
7 | #'
8 | #' @return A data frame containing values for \code{n} (number of cases),
9 | #' \code{missing} (number of missing cases), \code{mean}, \code{sd}, \code{min}, and \code{max}. \code{normal?}
10 | #' will contain yes/no for whether the variable is normally distributed based
11 | #' on the \code{\link{shapiro.test}} for the entire dataset
12 | #'
13 | #' @examples
14 | #'
15 | #' desc.all(neoOpen)
16 | #'
17 | #' @author Alexander Christensen
18 | #'
19 | #' @export
20 | #Variable Descriptive Statistics----
21 | desc.all <- function(data)
22 | {
23 | # Number of variables
24 | n <- ncol(data)
25 |
26 | # Descriptives list
27 | desc.list <- list()
28 |
29 | # Loop for descriptives
30 | for(i in 1:n)
31 | {
32 | # Check for variables that are factors
33 | # that can be converted to numeric
34 | if(is.factor(data[,i]))
35 | {data[,i] <- suppressWarnings(as.numeric(levels(data[,i]))[data[,i]])}
36 |
37 | # If variables are numeric,
38 | # then get descriptives
39 | if(all(is.numeric(data[,i])))
40 | {desc.list[[colnames(data)[i]]] <- desc(data,i,histplot=FALSE)}
41 | }
42 |
43 | # Get number of descriptive variables
44 | len <- length(desc.list)
45 |
46 | # Initialize descriptive matrix
47 | desc.mat <- matrix(NA,nrow=len,ncol=7)
48 | # Initialize variable name vector
49 | name <- vector("character",length=len)
50 |
51 | # Loop for descriptive matrix
52 | for(i in 1:len)
53 | {
54 | # Grab names
55 | name[i] <- names(desc.list[i])
56 |
57 | # Grab descriptives
58 | desc.mat[i,] <- t(data.frame(unlist(desc.list[[i]]),stringsAsFactors = FALSE))
59 | }
60 |
61 | # Convert descriptive matrix to a data frame
62 | desc.df <- as.data.frame(desc.mat)
63 |
64 | # Change column names to descriptives
65 | colnames(desc.df) <- c("n","missing","mean","sd","min","max","normal?")
66 | # Change row names to variable names
67 | row.names(desc.df) <- name
68 |
69 | return(desc.df)
70 | }
71 | #----
--------------------------------------------------------------------------------
/R/distance.R:
--------------------------------------------------------------------------------
1 | #' Distance
2 | #' @description Computes distance matrix of the network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param weighted Is the network weighted?
7 | #' Defaults to \code{FALSE}.
8 | #' Set to \code{TRUE} for weighted measure of distance
9 | #'
10 | #' @return A distance matrix of the network
11 | #'
12 | #' @examples
13 | #' # Pearson's correlation only for CRAN checks
14 | #' A <- TMFG(neoOpen, normal = FALSE)$A
15 | #'
16 | #' #Unweighted
17 | #' Du <- distance(A)
18 | #'
19 | #' #Weighted
20 | #' Dw <- distance(A, weighted = TRUE)
21 | #'
22 | #' @references
23 | #' Rubinov, M., & Sporns, O. (2010).
24 | #' Complex network measures of brain connectivity: Uses and interpretations.
25 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
26 | #'
27 | #' @author Alexander Christensen
28 | #'
29 | #' @export
30 | #Distance----
31 | distance<-function (A, weighted = FALSE)
32 | {
33 | if(nrow(A)!=ncol(A))
34 | {stop("Input not an adjacency matrix")}
35 | if(!weighted)
36 | {B<-ifelse(A!=0,1,0)
37 | l<-1
38 | Lpath<-B
39 | D<-B
40 | Idx<-matrix(TRUE,nrow=nrow(B),ncol=ncol(B))
41 | while(any(Idx))
42 | {
43 | l<-l+1
44 | Lpath<-(as.matrix(Lpath))%*%(as.matrix(B))
45 | for(e in 1:nrow(Lpath))
46 | for(w in 1:ncol(Lpath))
47 | Idx[e,w]<-(Lpath[e,w]!=0&&(D[e,w]==0))
48 | D[Idx]<-l
49 | }
50 |
51 | D[!D]<-Inf
52 | diag(D)<-0
53 | }else if(weighted){
54 | G<-ifelse(1/A==Inf,0,1/A)
55 |
56 | if(any(G==-Inf))
57 | {G<-ifelse(G==-Inf,0,G)}
58 |
59 | if(any(!G==t(G)))
60 | {if(max(abs(G-t(G)))<1e-10)
61 | {G<-(G+G)/2}}
62 |
63 | n<-ncol(G)
64 | D<-matrix(Inf,nrow=n,ncol=n)
65 | diag(D)<-0
66 | B<-matrix(0,nrow=n,ncol=n)
67 |
68 | for(u in 1:n)
69 | {
70 | S<-matrix(TRUE,nrow=n,ncol=1)
71 | L1<-G
72 | V<-u
73 | while(TRUE)
74 | {
75 | S[V]<-0
76 | L1[,V]<-0
77 | for(v in V)
78 | {
79 | W<-which(L1[v,]!=0)
80 | d<-apply(rbind(D[u,W],(D[u,v]+L1[v,W])),2,min)
81 | wi<-apply(rbind(D[u,W],(D[u,v]+L1[v,W])),2,which.min)
82 | D[u,W]<-d
83 | ind<-W[wi==2]
84 | B[u,ind]<-B[u,v]+1
85 | }
86 |
87 | minD<-suppressWarnings(min(D[u,S==TRUE]))
88 | if(length(minD)==0||is.infinite(minD)){break}
89 |
90 | V<-which(D[u,]==minD)
91 | }
92 | }
93 | }
94 |
95 | D<-ifelse(D==Inf,0,D)
96 |
97 | colnames(D)<-colnames(A)
98 | row.names(D)<-colnames(A)
99 | return(D)
100 | }
101 | #----
--------------------------------------------------------------------------------
/R/diversity.R:
--------------------------------------------------------------------------------
1 | #' Diversity Coefficient
2 | #' @description Computes the diversity coefficient for each node. The diversity
3 | #' coefficient measures a node's connections to communitites outside of its
4 | #' own community. Nodes that have many connections to other communities will
5 | #' have higher diversity coefficient values. Positive and negative signed weights
6 | #' for diversity coefficients are computed separately.
7 | #'
8 | #' @param A Network adjacency matrix
9 | #'
10 | #' @param comm A vector of corresponding to each item's community.
11 | #' Defaults to \code{"walktrap"} for the \code{\link[igraph]{cluster_walktrap}} community detection algorithm.
12 | #' Set to \code{"louvain"} for the \code{\link[NetworkToolbox]{louvain}} community detection algorithm.
13 | #' Can also be set to user-specified communities (see examples)
14 | #'
15 | #' @return Returns a list containing:
16 | #'
17 | #' \item{overall}{Diversity coefficient without signs considered}
18 | #'
19 | #' \item{positive}{Diversity coefficient with only positive sign}
20 | #'
21 | #' \item{negative}{Diversity coefficient with only negative sign}
22 | #'
23 | #' @details
24 | #' Values closer to 1 suggest greater between-community connectivity and
25 | #' values closer to 0 suggest greater within-community connectivity
26 | #'
27 | #' @examples
28 | #' # Pearson's correlation only for CRAN checks
29 | #' A <- TMFG(neoOpen, normal = FALSE)$A
30 | #'
31 | #' #theoretical communities
32 | #' comm <- rep(1:8, each = 6)
33 | #'
34 | #' gdiv <- diversity(A, comm = comm)
35 | #'
36 | #' #walktrap communities
37 | #' wdiv <- diversity(A, comm = "walktrap")
38 | #'
39 | #' @references
40 | #' Rubinov, M., & Sporns, O. (2010).
41 | #' Complex network measures of brain connectivity: Uses and interpretations.
42 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
43 | #'
44 | #' @author Alexander Christensen
45 | #'
46 | #' @export
47 | #Diversity Coefficient----
48 | # Updated 01.05.2022
49 | diversity <- function (A, comm = c("walktrap","louvain"))
50 | {
51 | #convert to matrix
52 | A <- as.matrix(A)
53 |
54 | #nodes
55 | n <- ncol(A)
56 |
57 | #set diagonal to zero
58 | diag(A) <- 0
59 |
60 | #set communities
61 | if(missing(comm))
62 | {comm<-"walktrap"
63 | }else{comm<-comm}
64 |
65 |
66 | #check if comm is character
67 | if(is.character(comm))
68 | {
69 | if(length(comm) == 1)
70 | {
71 | facts <- switch(comm,
72 | walktrap = suppressWarnings(igraph::walktrap.community(convert2igraph(A))$membership),
73 | louvain = suppressWarnings(louvain(A)$community)
74 | )
75 | }else{
76 |
77 | uni <- unique(comm)
78 |
79 | facts <- comm
80 |
81 | for(i in 1:length(uni))
82 | {facts[which(facts==uni[i])] <- i}
83 |
84 | }
85 |
86 | }else{facts <- comm}
87 |
88 | #ensure communities are numeric
89 | facts <- as.numeric(facts)
90 |
91 | #number of communities
92 | m <- max(facts)
93 |
94 | ent <- function (A, facts)
95 | {
96 | S <- colSums(A)
97 | Snm <- matrix(0,nrow=n,ncol=m)
98 |
99 | for(i in 1:m)
100 | {
101 | if(is.vector(A[,which(facts==i)]))
102 | {Snm[,i] <- sum(A[,which(facts==i)])
103 | }else{Snm[,i] <- rowSums(A[,which(facts==i)])}
104 | }
105 |
106 | pnm <- Snm/(S*matrix(1,nrow=n,ncol=m))
107 | pnm[is.na(pnm)]<-0
108 | pnm[!pnm]<-1
109 |
110 | H <- -rowSums(pnm*log(pnm))/log(m)
111 |
112 | return(H)
113 | }
114 |
115 | Hpos <- ent(ifelse(A>0,A,0),facts)
116 | Hneg <- ent(ifelse(A<0,A,0),facts)
117 | Hov <- ent(A,facts)
118 |
119 | return(list(overall=Hov,positive=Hpos,negative=Hneg))
120 | }
121 | #----
--------------------------------------------------------------------------------
/R/eigenvector.R:
--------------------------------------------------------------------------------
1 | #' Eigenvector Centrality
2 | #' @description Computes eigenvector centrality of each node in a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param weighted Is the network weighted?
7 | #' Defaults to \code{TRUE}.
8 | #' Set to \code{FALSE} for unweighted measure of eigenvector centrality
9 | #'
10 | #' @return A vector of eigenvector centrality values for each node in the network
11 | #'
12 | #' @examples
13 | #' # Pearson's correlation only for CRAN checks
14 | #' A <- TMFG(neoOpen, normal = FALSE)$A
15 | #'
16 | #' #Weighted
17 | #' EC <- eigenvector(A)
18 | #'
19 | #' #Unweighted
20 | #' EC <- eigenvector(A, weighted = FALSE)
21 | #'
22 | #' @references
23 | #' Rubinov, M., & Sporns, O. (2010).
24 | #' Complex network measures of brain connectivity: Uses and interpretations.
25 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
26 | #'
27 | #' @author Alexander Christensen
28 | #'
29 | #' @export
30 | #Eigenvector----
31 | eigenvector <- function (A, weighted = TRUE)
32 | {
33 | if(nrow(A)!=ncol(A))
34 | {stop("Input not an adjacency matrix")}
35 |
36 | # A <- abs(A)
37 | A <- as.matrix(A)
38 |
39 | if(!weighted)
40 | {A <- binarize(A)}
41 | ec <- abs(eigen(A)$vectors[,1])
42 | ec <- as.vector(round(ec,3))
43 | names(ec) <- colnames(A)
44 |
45 | return(ec)
46 | }
47 | #----
--------------------------------------------------------------------------------
/R/flow.frac.R:
--------------------------------------------------------------------------------
1 | #' Flow Fraction
2 | #' @description Computes \code{\link[NetworkToolbox]{eigenvector}} centrality over nodes in a subset of nodes
3 | #' in the network. This measure generalizes across any subset of nodes and
4 | #' is not specific to communities
5 | #'
6 | #' @param A An adjacency matrix
7 | #'
8 | #' @param nodes A subset of nodes in the network
9 | #'
10 | #' @return Returns a flow fraction value
11 | #'
12 | #' @examples
13 | #' # Pearson's correlation only for CRAN checks
14 | #' A <- TMFG(neoOpen, normal = FALSE)$A
15 | #'
16 | #' nodes <- seq(1,48,2)
17 | #'
18 | #' result <- flow.frac(A, nodes)
19 | #'
20 | #' @references
21 | #' Giscard, P. L., & Wilson, R. C. (2018).
22 | #' A centrality measure for cycles and subgraphs II.
23 | #' \emph{Applied Network Science}, \emph{3}, 9.
24 | #'
25 | #' @author Alexander Christensen
26 | #'
27 | #' @export
28 | #Flow fraction
29 | flow.frac <- function (A, nodes)
30 | {
31 | #make network diagonal 0
32 | diag(A) <- 0
33 | #grab first eigenvalue
34 | eig <- eigen(A)$values[1]
35 | #grab number of nodes
36 | n <- ncol(A)
37 |
38 | #remove nodes from network
39 | A[nodes,] <- 0
40 | A[,nodes] <- 0
41 |
42 | #compute flow.frac
43 | eye <- matrix(0,nrow=n,ncol=n)
44 | diag(eye) <- 1
45 | res <- det(eye - 1/eig*A)
46 |
47 | return(res)
48 | }
49 | #----
50 |
--------------------------------------------------------------------------------
/R/hybrid.R:
--------------------------------------------------------------------------------
1 | #' Hybrid Centrality
2 | #' @description Computes hybrid centrality of each node in a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param BC How should the betweenness centrality be computed?
7 | #' Defaults to \code{"random"}.
8 | #' Set to \code{"standard"} for standard \code{\link[NetworkToolbox]{betweenness}}.
9 | #'
10 | #' @param beta Beta parameter to be passed to the \code{\link[NetworkToolbox]{rspbc}} function
11 | #' Defaults to .01
12 | #'
13 | #' @return A vector of hybrid centrality values for each node in the network
14 | #' (higher values are more central, lower values are more peripheral)
15 | #'
16 | #' @examples
17 | #' # Pearson's correlation only for CRAN checks
18 | #' A <- TMFG(neoOpen, normal = FALSE)$A
19 | #'
20 | #' HC <- hybrid(A)
21 | #' @references
22 | #' Christensen, A. P., Kenett, Y. N., Aste, T., Silvia, P. J., & Kwapil, T. R. (2018).
23 | #' Network structure of the Wisconsin Schizotypy Scales-Short Forms:
24 | #' Examining psychometric network filtering approaches.
25 | #' \emph{Behavior Research Methods}, \emph{50}, 2531-2550.
26 | #'
27 | #' Pozzi, F., Di Matteo, T., & Aste, T. (2013).
28 | #' Spread of risk across financial markets: Better to invest in the peripheries.
29 | #' \emph{Scientific Reports}, \emph{3}, 1655.
30 | #'
31 | #' @author Alexander Christensen
32 | #'
33 | #' @export
34 | #Hybrid Centality----
35 | hybrid <- function (A, BC = c("standard","random"), beta)
36 | {
37 | A <- abs(A)
38 | A <- as.matrix(A)
39 |
40 | if(missing(BC))
41 | {BC<-"random"
42 | }else{BC<-match.arg(BC)}
43 |
44 | if(missing(beta))
45 | {beta<-.01
46 | }else{beta<-beta}
47 |
48 | if(nrow(A)!=ncol(A))
49 | {stop("Input not an adjacency matrix")}
50 | if(BC=="standard")
51 | {
52 | BCu<-betweenness(A,weighted=FALSE)
53 | BCw<-betweenness(A)
54 | }else if(BC=="random")
55 | {
56 | BCu<-rspbc(binarize(A),beta=beta)
57 | BCw<-rspbc(A,beta=beta)
58 | }
59 |
60 | CCu<-closeness(A,weighted=FALSE)
61 | CCw<-closeness(A)
62 | if(isSymmetric(A, check.attributes = FALSE))
63 | {Deg<-degree(A)
64 | }else{Deg<-degree(A)$outDeg}
65 | if(isSymmetric(A, check.attributes = FALSE))
66 | {Str<-strength(A)
67 | }else{Str<-strength(A)$outStr}
68 | ECu<-eigenvector(A,weighted=FALSE)
69 | ECw<-eigenvector(A)
70 | #levu<-leverage(A,weighted=FALSE)
71 | #levw<-leverage(A)
72 | #Eu<-PathLengths(A,weighted=FALSE)$ecc
73 | #Ew<-PathLengths(A)$ecc
74 |
75 | hyb<-((rank(BCu,ties.method="max")+
76 | rank(BCw,ties.method="max")+
77 | rank(CCu,ties.method="max")+
78 | rank(CCw,ties.method="max")+
79 | rank(Deg,ties.method="max")+
80 | rank(Str,ties.method="max")+
81 | rank(ECu,ties.method="max")+
82 | rank(ECw,ties.method="max")-
83 | #rank(levu,ties.method="max")+
84 | #rank(levw,ties.method="max")-
85 | #rev(rank(Eu,ties.method="max"))+
86 | #rev(rank(Ew,ties.method="max"))-
87 | 8)/(8*((ncol(A))-1)))
88 |
89 | hyb<-round(as.vector(hyb),3)
90 |
91 | names(hyb) <- colnames(A)
92 |
93 | return(hyb)
94 | }
95 | #----
--------------------------------------------------------------------------------
/R/impact.R:
--------------------------------------------------------------------------------
1 | #' Node Impact
2 | #' @description Computes impact measure or how much the average distance in the
3 | #' network changes with that node removed of each node in a network
4 | #' (\strong{Please see and cite Kenett et al., 2011})
5 | #'
6 | #' @param A An adjacency matrix of network data
7 | #'
8 | #' @return A vector of node impact values for each node in the network
9 | #' (impact > 0, greater ASPL when node is removed; impact < 0,
10 | #' lower ASPL when node is removed)
11 | #'
12 | #' @examples
13 | #' # normal set to FALSE for CRAN tests
14 | #' A <- TMFG(neoOpen, normal = FALSE)$A
15 | #'
16 | #' nodeimpact <- impact(A)
17 | #'
18 | #' @references
19 | #' Cotter, K. N., Christensen, A. P., & Silvia, P. J. (in press).
20 | #' Understanding inner music: A dimensional approach to musical imagery.
21 | #' \emph{Psychology of Aesthetics, Creativity, and the Arts}.
22 | #'
23 | #' Kenett, Y. N., Kenett, D. Y., Ben-Jacob, E., & Faust, M. (2011).
24 | #' Global and local features of semantic networks: Evidence from the Hebrew mental lexicon.
25 | #' \emph{PLoS one}, \emph{6}, e23912.
26 | #'
27 | #' @author Alexander Christensen
28 | #'
29 | #' @export
30 | #Node Impact----
31 | impact <- function (A)
32 | {
33 | allP <- pathlengths(A)$ASPL
34 | remove <- matrix(0,nrow=nrow(A),ncol=1)
35 |
36 | pb <- txtProgressBar(max=ncol(A), style = 3)
37 |
38 | for(j in 1:ncol(A))
39 | {
40 | remove[j,]<-(pathlengths(A[-j,-j])$ASPL)-allP
41 |
42 | setTxtProgressBar(pb, j)
43 | }
44 |
45 | close(pb)
46 |
47 | remove <- as.vector(round(remove,3))
48 | names(remove) <- colnames(A)
49 |
50 | return(remove)
51 | }
52 | #----
--------------------------------------------------------------------------------
/R/is.graphical.R:
--------------------------------------------------------------------------------
1 | #' Determines if Network is Graphical
2 | #' @description Tests for whether the network is graphical.
3 | #' Input must be a partial correlation network.
4 | #' Function assumes that partial correlations were computed from a multivariate normal distribution
5 | #'
6 | #' @param A A partial correlation network (adjacency matrix)
7 | #'
8 | #' @return Returns a TRUE/FALSE for whether network is graphical
9 | #'
10 | #' @examples
11 | #' \dontrun{
12 | #' A <- LoGo(neoOpen, normal = TRUE, partial = TRUE)
13 | #'
14 | #' is.graphical(A)
15 | #' }
16 | #'
17 | #' @author Alexander Christensen
18 | #'
19 | #' @export
20 | #Is network graphical?----
21 | is.graphical <- function (A)
22 | {
23 | #make diagonal 1
24 | diag(A)<-1
25 |
26 | #covert partial correlations to covariance
27 | I<-diag(1, dim(A)[1])
28 |
29 | #compute covariance matrix
30 | error<-try(solve(I-A)%*%t(solve(I-A)),silent=TRUE)
31 | if(is.character(error))
32 | {ret<-FALSE
33 | }else{covmat<-solve(I-A)%*%t(solve(I-A))}
34 |
35 | #covert to inverse covariance
36 | error<-try(solve(covmat),silent=TRUE)
37 | if(is.character(error))
38 | {ret<-FALSE
39 | }else{inv<-solve(covmat)
40 |
41 | #reduce small values to 0
42 | check<-zapsmall(inv)
43 |
44 |
45 | error<-try(any(eigen(check)$values<0),silent=TRUE)
46 | if(is.character(error))
47 | {ret<-FALSE
48 | }else if(any(eigen(check)$values<0))
49 | {ret<-FALSE
50 | }else{ret<-TRUE}
51 | }
52 | return(ret)
53 | }
54 | #----
--------------------------------------------------------------------------------
/R/kld.R:
--------------------------------------------------------------------------------
1 | #' Kullback-Leibler Divergence
2 | #' @description Estimates the Kullback-Leibler Divergence which measures how one probability distribution
3 | #' diverges from the original distribution (equivalent means are assumed)
4 | #' Matrices \strong{must} be positive definite inverse covariance matrix for accurate measurement.
5 | #' This is a \strong{relative} metric
6 | #'
7 | #' @param base Full or base model
8 | #'
9 | #' @param test Reduced or testing model
10 | #'
11 | #' @return A value greater than 0.
12 | #' Smaller values suggest the probability distribution of the reduced model is near the full model
13 | #'
14 | #' @examples
15 | #' A1 <- solve(cov(neoOpen))
16 | #'
17 | #' \dontrun{
18 | #' A2 <- LoGo(neoOpen)
19 | #'
20 | #' kld_value <- kld(A1, A2)
21 | #' }
22 | #'
23 | #' @references
24 | #' Kullback, S., & Leibler, R. A. (1951).
25 | #' On information and sufficiency.
26 | #' \emph{The Annals of Mathematical Statistics}, \emph{22}, 79-86.
27 | #'
28 | #' @author Alexander Christensen
29 | #'
30 | #' @export
31 | #Kullback Leibler Divergence----
32 | kld <- function (base, test)
33 | {
34 | if(nrow(base)!=ncol(base))
35 | {base <- solve(cov(base))}
36 |
37 | if(nrow(test)!=ncol(test))
38 | {stop("Test must be an adjacency matrix")}
39 |
40 | kl1 <- sum(diag(solve(base)%*%test)) - log(det(solve(base)%*%test)) - ncol(base)
41 | kl2 <- sum(diag(solve(test)%*%base)) - log(det(solve(test)%*%base)) - ncol(test)
42 |
43 | kl <- log(kl1 + kl2)
44 |
45 | return(kl)
46 | }
47 | #----
--------------------------------------------------------------------------------
/R/lattnet.R:
--------------------------------------------------------------------------------
1 | #' Generates a Lattice Network
2 | #' @description Generates a lattice network
3 | #'
4 | #' @param nodes Number of nodes in lattice network
5 | #'
6 | #' @param edges Number of edges in lattice network
7 | #'
8 | #' @return Returns an adjacency matrix of a lattice network
9 | #'
10 | #' @examples
11 | #' latt <- lattnet(10, 27)
12 | #'
13 | #' @references
14 | #' Rubinov, M., & Sporns, O. (2010).
15 | #' Complex network measures of brain connectivity: Uses and interpretations.
16 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
17 | #'
18 | #' @author Alexander Christensen
19 | #'
20 | #' @export
21 | #Lattice Network----
22 | #Updated 12.05.2021
23 | lattnet <- function (nodes, edges)
24 | {
25 | dlat<-matrix(0,nrow=nodes,ncol=nodes)
26 | lat<-matrix(0,nrow=nodes,ncol=nodes)
27 |
28 | balance <- sum(lat) - edges
29 |
30 | count <- 0
31 |
32 | while(sign(balance) == -1){
33 |
34 | if(count == 0){
35 |
36 | for(i in 1:nodes){
37 |
38 | if(i != nodes){
39 | dlat[i, (i + 1)] <- 1
40 | }
41 | }
42 |
43 | }else{
44 |
45 | for(i in 1:nodes){
46 |
47 | if(i < (nodes - count)){
48 | dlat[i, (i + (count + 1))] <- 1
49 | }
50 |
51 | }
52 |
53 | }
54 |
55 | count <- count + 1
56 |
57 | balance <- sum(dlat) - edges
58 |
59 | }
60 |
61 | over <- sum(dlat) - edges
62 |
63 | if(over != 0){
64 |
65 | rp <- sample(which(dlat==1), over, replace = FALSE)
66 |
67 | dlat[rp] <- 0
68 |
69 | }
70 |
71 | lat <- dlat + t(dlat)
72 |
73 | return(lat)
74 | }
75 | #----
--------------------------------------------------------------------------------
/R/leverage.R:
--------------------------------------------------------------------------------
1 | #' Leverage Centrality
2 | #' @description Computes leverage centrality of each node in a network
3 | #' (the degree of connected neighbors; \strong{Please see and cite Joyce et al., 2010})
4 | #'
5 | #' @param A An adjacency matrix of network data
6 | #'
7 | #' @param weighted Is the network weighted?
8 | #' Defaults to \code{TRUE}.
9 | #' Set to \code{FALSE} for unweighted measure of leverage centrality
10 | #'
11 | #' @return A vector of leverage centrality values for each node in the network
12 | #'
13 | #' @examples
14 | #' # Pearson's correlation only for CRAN checks
15 | #' A <- TMFG(neoOpen, normal = FALSE)$A
16 | #'
17 | #' #Weighted
18 | #' levW <- leverage(A)
19 | #'
20 | #' #Unweighted
21 | #' levU <- leverage(A, weighted = FALSE)
22 | #'
23 | #' @references
24 | #' Joyce, K. E., Laurienti, P. J., Burdette, J. H., & Hayasaka, S. (2010).
25 | #' A new measure of centrality for brain networks.
26 | #' \emph{PLoS One}, \emph{5} e12200.
27 | #'
28 | #' @author Alexander Christensen
29 | #'
30 | #' @export
31 | #Leverage Centrality----
32 | leverage <- function (A, weighted = TRUE)
33 | {
34 | if(nrow(A)!=ncol(A))
35 | {stop("Input not an adjacency matrix")}
36 |
37 | if(!weighted)
38 | {B<-binarize(A)
39 | }else{B<-A}
40 |
41 | con<-colSums(B)
42 |
43 | lev<-matrix(1,nrow=nrow(B),ncol=1)
44 |
45 | for(i in 1:ncol(B))
46 | {lev[i]<-(1/con[i])*sum((con[i]-con[which(B[,i]!=0)])/(con[i]+con[which(B[,i]!=0)]))}
47 |
48 | for(i in 1:nrow(lev))
49 | if(is.na(lev[i,]))
50 | {lev[i,]<-0}
51 |
52 | lev <- as.vector(lev)
53 |
54 | names(lev) <- colnames(A)
55 |
56 | return(lev)
57 | }
58 | #----
--------------------------------------------------------------------------------
/R/louvain.R:
--------------------------------------------------------------------------------
1 | #' Louvain Community Detection Algorithm
2 | #' @description Computes a vector of communities (community) and a global modularity measure (Q)
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param gamma Defaults to \code{1}.
7 | #' Set to \code{gamma} > 1 to detect smaller modules and \code{gamma} < 1 for larger modules
8 | #'
9 | #' @param M0 Input can be an initial community vector.
10 | #' Defaults to \code{NULL}
11 | #'
12 | #' @return Returns a list containing:
13 | #'
14 | #' \item{community}{A community vector corresponding to each node's community}
15 | #'
16 | #' \item{Q}{Modularity statistic. A measure of how well the communities are compartmentalized}
17 | #'
18 | #' @examples
19 | #' # Pearson's correlation only for CRAN checks
20 | #' A <- TMFG(neoOpen, normal = FALSE)$A
21 | #'
22 | #' modularity <- louvain(A)
23 | #'
24 | #' @references
25 | #' Blondel, V. D., Guillaume, J. L., Lambiotte, R., & Lefebvre, E. (2008).
26 | #' Fast unfolding of communities in large networks.
27 | #' \emph{Journal of Statistical Mechanics: Theory and Experiment}, \emph{2008}, P10008.
28 | #'
29 | #' Rubinov, M., & Sporns, O. (2010).
30 | #' Complex network measures of brain connectivity: Uses and interpretations.
31 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
32 | #'
33 | #' @author Alexander Christensen
34 | #'
35 | #' @export
36 | #Louvain Community Detection----
37 | louvain <- function (A, gamma, M0)
38 | {
39 | if(missing(gamma))
40 | {gamma<-1
41 | }else{gamma<-gamma}
42 |
43 | if(missing(M0))
44 | {M0<-1:ncol(A)
45 | }else(M0<-M0)
46 |
47 | diag(A) <- 0
48 |
49 | n<-ncol(A)
50 | s<-sum(A)
51 |
52 | if(min(A)<0)
53 | {warning("Matrix contains negative weights: absolute weights were used")
54 | A<-abs(A)}
55 |
56 | Mb<-M0
57 | M<-M0
58 |
59 | mat<-matrix(0,nrow=n,ncol=n)
60 | for(i in 1:n)
61 | for(j in 1:n)
62 | {mat[i,j]<-(colSums(A)[i]*rowSums(A)[j])/s}
63 |
64 | B<-A-(gamma*(mat))
65 |
66 | B<-(B+t(B))/2
67 |
68 | Hnm<-matrix(0,nrow=nrow(A),ncol=(length(unique(Mb))))
69 |
70 |
71 | for(m in 1:max(Mb))
72 | {
73 | if(!is.null(nrow(B[,which(Mb==m)])))
74 | {Hnm[,m]<-rowSums(B[,which(Mb==m)])
75 | }else{Hnm[,m]<-B[,which(Mb==m)]}
76 | }
77 |
78 | H<-colSums(Hnm)
79 | Hm<-rowSums(Hnm)
80 |
81 | Q0<-(-Inf)
82 | bsxfun<-matrix(0,nrow=n,ncol=n)
83 | diag(bsxfun)<-1
84 | Q<-sum(diag(as.matrix(B)*bsxfun))/s
85 |
86 |
87 | first_iter<-TRUE
88 | while(Q-Q0>0)
89 | {
90 | flag<-TRUE
91 | while(flag)
92 | {
93 | set.seed(0)
94 | flag<-FALSE
95 | for(u in sample(n))
96 | {
97 | ma<-Mb[u]
98 | dQ<-Hnm[u,] - Hnm[u,ma] + B[u,u]
99 | dQ[ma]<-0
100 |
101 | max_dQ<-max(dQ)
102 | mb<-which.max(dQ)
103 |
104 | if(max_dQ>0)
105 | {
106 | flag<-TRUE
107 | Mb[u]<-mb
108 |
109 | Hnm[,mb]<-Hnm[,mb]+B[,u]
110 | Hnm[,ma]<-Hnm[,ma]-B[,u]
111 | Hm[mb]<-Hm[mb]+H[u]
112 | Hm[ma]<-Hm[ma]-H[u]
113 | }
114 | }
115 | }
116 | Mb<-match(Mb,unique(Mb))
117 |
118 | M0<-M
119 | if(first_iter)
120 | {
121 | M<-Mb
122 | first_iter<-FALSE
123 | }else{
124 | for(u in 1:n)
125 | {
126 | M[M0==u]<-Mb[u]
127 | }
128 | }
129 |
130 | n<-max(Mb)
131 | B1<-matrix(0,nrow=n,ncol=n)
132 | for(u in 1:n)
133 | for(v in u:n)
134 | {
135 | bm<-sum(sum(B[Mb==u,Mb==v]))
136 | B1[u,v]<-bm
137 | B1[v,u]<-bm
138 | }
139 | B<-B1
140 |
141 | Mb<-1:n
142 | Hnm<-B
143 | H<-colSums(B)
144 |
145 | Q0<-Q
146 |
147 | Q<-sum(diag(B))/s
148 |
149 | }
150 | return(list(community=M,Q=Q))
151 | }
152 | #----
--------------------------------------------------------------------------------
/R/neoOpen.R:
--------------------------------------------------------------------------------
1 | #NEO-PI-3 Openness to Experience Data----
2 | #'NEO-PI-3 Openness to Experience Data
3 | #'
4 | #' A response matrix (\emph{n} = 802) of NEO-PI-3's Openness to Experience
5 | #' from Christensen, Cotter, & Silvia (2019).
6 | #'
7 | #' @name neoOpen
8 | #'
9 | #' @docType data
10 | #'
11 | #' @usage data(neoOpen)
12 | #'
13 | #' @format A 802x48 response matrix
14 | #'
15 | #' @keywords datasets
16 | #'
17 | #' @references
18 | #' Christensen, A. P., Cotter, K. N., & Silvia, P. J. (2019).
19 | #' Reopening openness to experience: A network analysis of four openness to experience inventories.
20 | #' \emph{Journal of Personality Assessment}, \emph{101}, 574-588.
21 | #'
22 | #' @examples
23 | #' data("neoOpen")
24 | #'
25 | NULL
26 | #----
--------------------------------------------------------------------------------
/R/net.coverage.R:
--------------------------------------------------------------------------------
1 | #' Network Coverage
2 | #' @description Computes the mean distance across a subset of nodes in a network.
3 | #' This measure can be used to identify the effectiveness of a subset of nodes'
4 | #' coverage of the network space
5 | #'
6 | #' @param A An adjacency matrix
7 | #'
8 | #' @param nodes Subset of nodes to examine the coverage of the network
9 | #'
10 | #' @param weighted Is the network weighted?
11 | #' Defaults to \code{FALSE}.
12 | #' Set to \code{TRUE} for weighted measures
13 | #'
14 | #' @return Returns a list containing:
15 | #'
16 | #' \item{mean}{The average distance from the subset of nodes to all other nodes in the network}
17 | #'
18 | #' \item{sd}{The standard deviation of distance from the subset of nodes to all other nodes in the network}
19 | #'
20 | #' \item{range}{The range of distance from the subset of nodes to all other nodes in the network}
21 | #'
22 | #' @examples
23 | #' # Pearson's correlation only for CRAN checks
24 | #' A <- TMFG(neoOpen, normal = FALSE)$A
25 | #'
26 | #' nodes <- seq(1,48,2)
27 | #'
28 | #' result <- net.coverage(A, nodes)
29 | #'
30 | #' @references
31 | #' Christensen, A. P., Cotter, K. N., Silvia, P. J., & Benedek, M. (2018)
32 | #' Scale development via network analysis: A comprehensive and concise measure of Openness to Experience
33 | #' \emph{PsyArXiv}, 1-40.
34 | #'
35 | #' @author Alexander Christensen and
36 | #' Mathias Benedek
37 | #'
38 | #' @export
39 | #Network Coverage----
40 | net.coverage <- function (A, nodes, weighted = FALSE)
41 | {
42 | fnames <- colnames(A)
43 |
44 | if(is.numeric(nodes))
45 | {inames <- colnames(A)[nodes]
46 | }else{inames <- nodes}
47 |
48 | dist <- distance(A, weighted = weighted)
49 |
50 | diag(dist) <- Inf
51 |
52 | sdist <- dist[fnames,inames]
53 |
54 | res <- list()
55 |
56 | res$mean <- mean(apply(sdist,1,min))
57 | res$sd <- sd(apply(sdist,1,min))
58 | res$range <- range(apply(sdist,1,min))
59 | res$dist <- apply(sdist,1,min)
60 |
61 | return(res)
62 | }
63 | #----
--------------------------------------------------------------------------------
/R/network.coverage.R:
--------------------------------------------------------------------------------
1 | #' Network Coverage
2 | #' @description Computes the mean distance across a subset of nodes in a network.
3 | #' This measure can be used to identify the effectiveness of a subset of nodes'
4 | #' coverage of the network space
5 | #'
6 | #' @param A An adjacency matrix
7 | #'
8 | #' @param nodes Subset of nodes to examine the coverage of the network
9 | #'
10 | #' @param weighted Is the network weighted?
11 | #' Defaults to \code{FALSE}.
12 | #' Set to \code{TRUE} for weighted measures
13 | #'
14 | #' @return Returns a list containing:
15 | #'
16 | #' \item{mean}{The average distance from the subset of nodes to all other nodes in the network}
17 | #'
18 | #' \item{sd}{The standard deviation of distance from the subset of nodes to all other nodes in the network}
19 | #'
20 | #' \item{range}{The range of distance from the subset of nodes to all other nodes in the network}
21 | #'
22 | #' @examples
23 | #' # Pearson's correlation only for CRAN checks
24 | #' A <- TMFG(neoOpen, normal = FALSE)$A
25 | #'
26 | #' nodes <- seq(1,48,2)
27 | #'
28 | #' result <- network.coverage(A, nodes)
29 | #'
30 | #' @references
31 | #' Christensen, A. P., Cotter, K. N., Silvia, P. J., & Benedek, M. (2018)
32 | #' Scale development via network analysis: A comprehensive and concise measure of Openness to Experience
33 | #' \emph{PsyArXiv}, 1-40.
34 | #'
35 | #' @author Alexander Christensen and Mathias Benedek
36 | #'
37 | #' @export
38 | #Network Coverage----
39 | network.coverage <- function (A, nodes, weighted = FALSE)
40 | {
41 | fnames <- colnames(A)
42 |
43 | if(is.numeric(nodes))
44 | {inames <- colnames(A)[nodes]
45 | }else{inames <- nodes}
46 |
47 | dist <- distance(A, weighted = weighted)
48 |
49 | diag(dist) <- Inf
50 |
51 | sdist <- dist[fnames,inames]
52 |
53 | res <- list()
54 |
55 | res$mean <- mean(apply(sdist,1,min))
56 | res$sd <- sd(apply(sdist,1,min))
57 | res$range <- range(apply(sdist,1,min))
58 | res$dist <- apply(sdist,1,min)
59 |
60 | return(res)
61 | }
62 | #----
--------------------------------------------------------------------------------
/R/neuralnetfilter.R:
--------------------------------------------------------------------------------
1 | #' Neural Network Filter
2 | #' @description Applies a network filtering methodology to neural network array.
3 | #' Removes edges from the neural network output from \code{\link{convertConnBrainMat}}
4 | #' using a network filtering approach
5 | #'
6 | #' @param neuralarray Array from \code{\link{convertConnBrainMat}} function
7 | #'
8 | #' @param method Filtering method to be applied
9 | #'
10 | #' @param progBar Should progress bar be displayed?
11 | #' Defaults to \code{TRUE}.
12 | #' Set \code{FALSE} for no progress bar
13 | #'
14 | #' @param ... Additional arguments from network filtering methods
15 | #'
16 | #' @return Returns an array of n x n x m filtered matrices
17 | #'
18 | #' @examples
19 | #' \dontrun{neuralarray <- convertConnBrainMat()
20 | #'
21 | #' filteredneuralarray <- neuralnetfilter(neuralarray, method = "threshold", thresh = .50)
22 | #'
23 | #' dependencyarray <- depna(neuralarray)
24 | #'
25 | #' filtereddependencyarray <- neuralnetfilter(dependencyarray, method = "TMFG", depend = TRUE)
26 | #' }
27 | #'
28 | #' @author Alexander Christensen
29 | #'
30 | #' @export
31 | #Neural Network Filter----
32 | neuralnetfilter <- function (neuralarray, method = c("TMFG","MaST","ECOplusMaST","ECO","threshold"),progBar = TRUE, ...)
33 | {
34 | if(missing(method))
35 | {method<-"TMFG"
36 | }else{method<-match.arg(method)}
37 |
38 | n<-length(neuralarray)/nrow(neuralarray)/ncol(neuralarray)
39 |
40 | for(i in 1:n)
41 | if(nrow(neuralarray)!=ncol(neuralarray))
42 | {stop(paste("Participant ",i,"'s matrix is not symmetric",sep=""))}
43 |
44 | filarray<-neuralarray
45 |
46 | if(progBar)
47 | {pb <- txtProgressBar(max=n, style = 3)}
48 |
49 | for(i in 1:n)
50 | {
51 | if(method=="TMFG")
52 | {filarray[,,i]<-TMFG(neuralarray[,,i],...)$A
53 | }else if(method=="MaST")
54 | {filarray[,,i]<-MaST(neuralarray[,,i],...)
55 | }else if(method=="ECO")
56 | {filarray[,,i]<-ECO(neuralarray[,,i],...)
57 | }else if(method=="ECOplusMaST")
58 | {filarray[,,i]<-ECOplusMaST(neuralarray[,,i],...)
59 | }else if(method=="threshold")
60 | {filarray[,,i]<-threshold(neuralarray[,,i],...)$A
61 | }else{stop("Method not available")}
62 | if(progBar){setTxtProgressBar(pb, i)}
63 | }
64 | if(progBar){close(pb)}
65 |
66 | return(filarray)
67 | }
68 | #----
--------------------------------------------------------------------------------
/R/openness.R:
--------------------------------------------------------------------------------
1 | #Openness to Experience----
2 | #' Four Inventories of Openness to Experience
3 | #'
4 | #' A response matrix (\emph{n} = 794) of all four Openness to Experience
5 | #' inventories from Christensen, Cotter, & Silvia (2019). The
6 | #' key provides inventory, facet, and item description information
7 | #' for the item labels. Note that because of NEO's copyrights the
8 | #' items have been shortened and paraphrased
9 | #'
10 | #' @name openness
11 | #'
12 | #' @aliases openness
13 | #' @aliases openness.key
14 | #'
15 | #' @docType data
16 | #'
17 | #' @usage data(openness)
18 | #' @usage data(openness.key)
19 | #'
20 | #' @format A 794 x 138 response matrix (openness) and 138 x 7 matrix (openness.key).
21 | #' Here are detailed descriptions of the key:
22 | #'
23 | #' \itemize{
24 | #'
25 | #' \item \code{Inventory} --- The personality inventory the item belongs to
26 | #'
27 | #' \item \code{Facet} --- The personality inventory defined facet
28 | #'
29 | #' \item \code{JPA.Domains} --- The broad domains identified by Christensen, Cotter, and Silvia (2019)
30 | #'
31 | #' \item \code{JPA.Facets} --- The facets identified by Christensen, Cotter, and Silvia (2019)
32 | #'
33 | #' \item \code{Item.Label} --- The labels used in Christensen, Cotter, and Silvia (2019)
34 | #'
35 | #' \item \code{Item.Description} --- Descriptions of each item. Note that the NEO-PI-3 items are protected by
36 | #' copyright and therefore have been paraphrased. These item descriptions
37 | #' do not represent the item as given to the participant
38 | #'
39 | #' \item \code{Reversed} --- Whether an item should be reversed or not (\code{openness} is already reversed)
40 | #'
41 | #' }
42 | #'
43 | #'
44 | #' @keywords datasets
45 | #'
46 | #' @references
47 | #' Christensen, A. P., Cotter, K. N., & Silvia, P. J. (2019).
48 | #' Reopening openness to experience: A network analysis of four openness to experience inventories.
49 | #' \emph{Journal of Personality Assessment}, \emph{101}, 574-588.
50 | #'
51 | #' @examples
52 | #' # Loading data
53 | #' data("openness")
54 | #' data("openness.key")
55 | #'
56 | #' # Change item labels
57 | #' colnames(openness) <- openness.key$Item.Description
58 | #'
59 | NULL
60 | #----
--------------------------------------------------------------------------------
/R/pathlengths.R:
--------------------------------------------------------------------------------
1 | #' Characteristic Path Lengths
2 | #' @description Computes global average shortest path length,
3 | #' local average shortest path length, eccentricity,
4 | #' and diameter of a network
5 | #'
6 | #' @param A An adjacency matrix of network data
7 | #'
8 | #' @param weighted Is the network weighted?
9 | #' Defaults to \code{FALSE}.
10 | #' Set to \code{TRUE} for weighted measures
11 | #'
12 | #' @return Returns a list containing:
13 | #'
14 | #' \item{ASPL}{Global average shortest path length}
15 | #'
16 | #' \item{ASPLi}{Local average shortest path length}
17 | #'
18 | #' \item{ecc}{Eccentricity (i.e., maximal shortest path length between a node and any other node)}
19 | #'
20 | #' \item{D}{Diameter of the network (i.e., the maximum of eccentricity)}
21 | #'
22 | #' @examples
23 | #' # Pearson's correlation only for CRAN checks
24 | #' A <- TMFG(neoOpen, normal = FALSE)$A
25 | #'
26 | #' #Unweighted
27 | #' PL <- pathlengths(A)
28 | #'
29 | #' #Weighted
30 | #' PL <- pathlengths(A, weighted = TRUE)
31 | #'
32 | #' @references
33 | #' Rubinov, M., & Sporns, O. (2010).
34 | #' Complex network measures of brain connectivity: Uses and interpretations.
35 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
36 | #'
37 | #' @author Alexander Christensen
38 | #'
39 | #' @export
40 | #Path Lengths----
41 | pathlengths <- function (A, weighted = FALSE)
42 | {
43 | if(nrow(A)!=ncol(A))
44 | {stop("Input not an adjacency matrix")}
45 | if(!weighted)
46 | {D<-distance(A,weighted=FALSE)}else if(weighted){D<-distance(A,weighted=TRUE)}
47 | n<-nrow(D)
48 | for(i in 1:ncol(D))
49 | for(j in 1:nrow(D))
50 | if(is.infinite(D[j,i]))
51 | {D[j,i]<-0}
52 | if(any(colSums(D)==0))
53 | {
54 | newD <- D
55 | newD[,(which(colSums(D)==0))] <- rep(NA,length(which(colSums(D)==0)))
56 | }else{newD <- D}
57 |
58 | aspli<-colSums(newD*(newD!=0))/(ncol(newD)-1)
59 | aspl<-mean(aspli,na.rm=TRUE)
60 |
61 | Emat<-(D*(D!=0))
62 |
63 | ecc<-matrix(nrow=nrow(Emat),ncol=1)
64 |
65 | for(i in 1:nrow(Emat))
66 | {ecc[i,]<-max(Emat[i,])}
67 |
68 | d<-max(ecc)
69 |
70 | ecc <- as.vector(ecc)
71 | names(ecc) <- colnames(A)
72 |
73 | aspli <- as.vector(aspli)
74 | names(aspli) <- colnames(A)
75 |
76 | return(list(ASPL=aspl,ASPLi=aspli,ecc=ecc,diameter=d))
77 | }
78 | #----
--------------------------------------------------------------------------------
/R/randnet.R:
--------------------------------------------------------------------------------
1 | #' Generates a Random Network
2 | #'
3 | #' @description Generates a random binary network
4 | #'
5 | #' @param nodes Numeric.
6 | #' Number of nodes in random network
7 | #'
8 | #' @param edges Numeric.
9 | #' Number of edges in random network
10 | #'
11 | #' @param A Matrix or data frame.
12 | #' An adjacency matrix (i.e., network) to be used to estimated a random network with
13 | #' fixed edges (allows for asymmetric network estimation)
14 | #'
15 | #' @return Returns an adjacency matrix of a random network
16 | #'
17 | #' @examples
18 | #' rand <- randnet(10, 27)
19 | #'
20 | #' @references
21 | #' Rubinov, M., & Sporns, O. (2010).
22 | #' Complex network measures of brain connectivity: Uses and interpretations.
23 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
24 | #'
25 | #' Csardi, G., & Nepusz, T. (2006).
26 | #' The \emph{igraph} software package for complex network research.
27 | #' \emph{InterJournal, Complex Systems}, 1695.
28 | #'
29 | #' @author Alexander Christensen
30 | #'
31 | #' @export
32 | # Random Network----
33 | # Updated 20.04.2020
34 | randnet <- function (nodes = NULL, edges = NULL, A = NULL)
35 | {
36 | if(is.null(A))
37 | {
38 | # Initialize matrix
39 | mat <- matrix(1, nrow = nodes, ncol = nodes)
40 |
41 | # Set diagonal to zero
42 | diag(mat) <- 0
43 |
44 | # Indices of upper diagonal
45 | ind <- ifelse(upper.tri(mat) == TRUE, 1, 0)
46 | i <- which(ind == 1)
47 |
48 | # Sample zeros and ones
49 | rp <- sample(length(i))
50 | # Get indices
51 | irp <- i[rp]
52 |
53 | # Initialize random matrix
54 | rand <- matrix(0, nrow = nodes, ncol = nodes)
55 |
56 | # Insert edges
57 | rand[irp[1:edges]] <- 1
58 |
59 | # Make symmetric
60 | rand <- rand + t(rand)
61 |
62 | }else{
63 |
64 | # Make diagonal of network zero
65 | diag(A) <- 0
66 |
67 | # Compute degree
68 | degrees <- NetworkToolbox::degree(A)
69 |
70 | # Get degrees based on directed or undirected
71 | # Use igraph
72 | if(is.list(degrees))
73 | {rand <- as.matrix(igraph::as_adj(igraph::sample_degseq(out.deg = degrees$outDegree, in.deg = degrees$inDegree, method = "vl")))
74 | }else{rand <- as.matrix(igraph::as_adj(igraph::sample_degseq(out.deg = degrees, method = "vl")))}
75 | }
76 |
77 | return(rand)
78 | }
79 | #----
--------------------------------------------------------------------------------
/R/reg.R:
--------------------------------------------------------------------------------
1 | #' Regression Matrix
2 | #' @description Computes regression such that one variable is regressed over all other variables
3 | #'
4 | #' @param data A dataset
5 | #'
6 | #' @param family Error distribution to be used in the regression model.
7 | #' Defaults to \code{"logistic"}.
8 | #' Set to any family used in function \code{\link[stats]{family}}
9 | #'
10 | #' @param symmetric Should matrix be symmetric?
11 | #' Defaults to \code{TRUE}, taking the mean of the two edge weights
12 | #' (i.e., \code{[i,j]} and \code{[j,i]})
13 | #' Set to \code{FALSE} for asymmetric weights
14 | #' (i.e., \code{[i,j]} does not equal \code{[j,i]})
15 | #'
16 | #' @return A matrix of fully regressed coefficients where
17 | #' one variable is regressed over all others
18 | #'
19 | #' @examples
20 | #' #binarize responses
21 | #' psyb <- ifelse(neoOpen>=4, 1, 0)
22 | #'
23 | #' \dontrun{
24 | #' #perform logistic regression
25 | #' mat <- reg(psyb)}
26 | #'
27 | #' @author Alexander Christensen
28 | #'
29 | #' @importFrom stats glm
30 | #'
31 | #' @export
32 | #Regression----
33 | reg <- function (data,
34 | family = c("binomial" ,"gaussian", "Gamma", "poisson"),
35 | symmetric = TRUE)
36 | {
37 | if(missing(family))
38 | {family<-"binomial"
39 | }else(family<-match.arg(family))
40 |
41 | n<-ncol(data)
42 |
43 | data<-as.data.frame(data)
44 |
45 | mat<-matrix(0,nrow=(n-1),ncol=n)
46 |
47 | pb <- txtProgressBar(max=n, style = 3)
48 | for(i in 1:ncol(data))
49 | {
50 | res<-cbind(data[,i],data[,-i])
51 | mat[,i]<-glm(res,family=family)$coefficients[2:(ncol(data))]
52 |
53 | setTxtProgressBar(pb, i)
54 | }
55 | close(pb)
56 |
57 | nmat<-matrix(0,nrow=n,ncol=n)
58 |
59 | for(i in 1:n)
60 | {
61 | if(i==1)
62 | {nmat[,i]<-c(0,mat[,i])
63 | }else if(i!=n)
64 | {nmat[,i]<-c(mat[1:(i-1),i],0,mat[i:nrow(mat),i])
65 | }else if(i==n)
66 | {nmat[,i]<-c(mat[,i],0)}
67 | }
68 |
69 | if(symmetric)
70 | {nmat<-(nmat+t(nmat))/2}
71 |
72 | row.names(nmat)<-colnames(data)
73 | colnames(nmat)<-colnames(data)
74 |
75 | return(nmat)
76 | }
77 | #----
--------------------------------------------------------------------------------
/R/rmse.R:
--------------------------------------------------------------------------------
1 | #' Root Mean Square Error
2 | #' @description Computes the root mean square error (RMSE) of a sparse model to a full model
3 | #'
4 | #' @param base Base (or full) model to be evaluated against
5 | #'
6 | #' @param test Reduced (or testing) model (e.g., a sparse correlation or covariance matrix)
7 | #'
8 | #' @return RMSE value (lower values suggest more similarity between the full and sparse model)
9 | #'
10 | #' @examples
11 | #' A1 <- solve(cov(neoOpen))
12 | #'
13 | #' \dontrun{
14 | #' A2 <- LoGo(neoOpen)
15 | #'
16 | #' root <- rmse(A1, A2)
17 | #' }
18 | #'
19 | #' @author Alexander Christensen
20 | #'
21 | #' @export
22 | #Root Mean Square Error----
23 | rmse <- function (base, test)
24 | {
25 | base <- as.vector(base)
26 | test <- as.vector(test)
27 |
28 | error <- base - test
29 |
30 | root <- sqrt(mean(error^2))
31 |
32 | return(root)
33 | }
34 | #----
--------------------------------------------------------------------------------
/R/rspbc.R:
--------------------------------------------------------------------------------
1 | #' Randomized Shortest Paths Betweenness Centrality
2 | #' @description Computes betweenness centrality based on randomized shortest paths
3 | #' of each node in a network
4 | #' (\strong{Please see and cite Kivimaki et al., 2016})
5 | #'
6 | #' @param A An adjacency matrix of network data
7 | #'
8 | #' @param beta Sets the beta parameter.
9 | #' Defaults to \code{0.01} (recommended).
10 | #' Beta > 0.01 measure gets closer to weighted
11 | #' betweenness centrality (10) and beta < 0.01
12 | #' measure gets closer to degree (.0001)
13 | #'
14 | #' @param comm Vector.
15 | #' Community vector containing a value for each node.
16 | #' Computes "bridge" RSPBC, where the number of times
17 | #' a node is used on a random path between to another community
18 | #'
19 | #' @return A vector of randomized shortest paths betweenness
20 | #' centrality values for each node in the network
21 | #'
22 | #' @examples
23 | #' # Pearson's correlation only for CRAN checks
24 | #' A <- TMFG(neoOpen, normal = FALSE)$A
25 | #'
26 | #' rspbc <- rspbc(A, beta=0.01)
27 | #'
28 | #' @references
29 | #' Kivimaki, I., Lebichot, B., Saramaki, J., & Saerens, M. (2016).
30 | #' Two betweenness centrality measures based on Randomized Shortest Paths.
31 | #' \emph{Scientific Reports}, \emph{6}, 19668.
32 | #'
33 | #' @author Alexander Christensen
34 | #'
35 | #' @export
36 | #Randomized Shortest Paths Betweennesss Centrality----
37 | rspbc <- function (A, beta = 0.01, comm = NULL)
38 | {
39 | if(nrow(A)!=ncol(A))
40 | {stop("Input not an adjacency matrix")}
41 |
42 | if(is.null(comm))
43 | {A <- abs(A)
44 | }else{A[A<0] <- 0}
45 |
46 | A <- as.matrix(A)
47 |
48 | n<-ncol(A)
49 | e<-matrix(1,nrow=n,ncol=1)
50 | I<-diag(1,nrow=nrow(A),ncol=ncol(A))
51 | degs<-as.matrix(A)%*%as.matrix(e)
52 |
53 | if(any(degs==0))
54 | {stop("Graph contains unconnected nodes")}
55 |
56 | D1<-matrix(0,nrow=nrow(I),ncol=ncol(I))
57 | for(i in 1:nrow(I))
58 | for(j in 1:ncol(I))
59 | if(I[i,j]==1)
60 | {D1[i,j]<-I[i,j]/degs[i]}
61 |
62 | Pref<-as.matrix(D1)%*%as.matrix(A)
63 |
64 | bets<-matrix(0,nrow=n,ncol=1)
65 | C<-1/A
66 | C<-as.matrix(C)
67 | C[is.infinite(C)]<-0
68 | W<-Pref*exp(-(beta)*C)
69 |
70 | #Bridge RSPBC
71 | if(!is.null(comm))
72 | {
73 | for(i in 1:length(unique(comm)))
74 | {
75 | combos <- t(combn(which(comm==unique(comm)[i]),2))
76 |
77 | for(j in 1:nrow(combos))
78 | {W[c(combos[j,]),c(combos[j,])] <- 0}
79 | }
80 | }
81 |
82 | Y<-I-W
83 | Z<-solve(Y,I)
84 | Zdiv<-1/Z
85 | Zdiv[Zdiv==Inf]<-0
86 | DZdiv<-matrix(0,nrow=nrow(Zdiv),ncol=ncol(Zdiv))
87 | diag(DZdiv)<-diag(Zdiv)
88 |
89 | bet<-diag(as.matrix(Z)%*%as.matrix(t(Zdiv-n*DZdiv))%*%as.matrix(Z))
90 | bet<-round(as.data.frame(bet),0)
91 | minimum <- min(bet) - 1
92 | bet <- bet - minimum
93 | bet<-as.vector(as.matrix(bet))
94 | names(bet)<-colnames(A)
95 | return(bet)
96 | }
97 | #----
--------------------------------------------------------------------------------
/R/smallworldness.R:
--------------------------------------------------------------------------------
1 | #' Small-worldness Measure
2 | #' @description Computes the small-worldness measure of a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param iter Number of random (or lattice) networks to generate,
7 | #' which are used to calculate the mean random ASPL and CC (or lattice)
8 | #'
9 | #' @param progBar Defaults to \code{FALSE}.
10 | #' Set to \code{TRUE} to see progress bar
11 | #'
12 | #' @param method Defaults to \code{"HG"} (Humphries & Gurney, 2008).
13 | #' Set to \code{"rand"} for the CC to be calculated using a random network or
14 | #' set to \code{"TJHBL"} for (Telesford et al., 2011) where CC is calculated from a lattice network
15 | #'
16 | #' @return Returns a list containing:
17 | #'
18 | #' \item{swm}{Small-worldness value}
19 | #'
20 | #' \item{rASPL}{Global average shortest path length from random network}
21 | #'
22 | #' \item{lrCCt}{When \code{"rand"}, clustering coefficient from a random network.
23 | #' When \code{"HG"}, transitivity from a random network.
24 | #' When \code{"TJHBL"}, clustering coefficient from a lattice network}
25 | #'
26 | #' @details
27 | #' For \code{"rand"}, values > 1 indicate a small-world network.
28 | #' For \code{"HG"}, values > 3 indicate a small-world network.
29 | #' For \code{"TJHBL"}, values near 0 indicate a small-world network,
30 | #' while < 0 indicates a more regular network and > 0 indicates a more random network
31 | #'
32 | #' @examples
33 | #' # Pearson's correlation only for CRAN checks
34 | #' A <- TMFG(neoOpen, normal = FALSE)$A
35 | #'
36 | #' \donttest{
37 | #' swmHG <- smallworldness(A, method="HG")
38 | #'
39 | #' swmRand <- smallworldness(A, method="rand")
40 | #'
41 | #' swmTJHBL <- smallworldness(A, method="TJHBL")}
42 | #'
43 | #' @references
44 | #' Humphries, M. D., & Gurney, K. (2008).
45 | #' Network 'small-world-ness': A quantitative method for determining canonical network equivalence.
46 | #' \emph{PLoS one}, \emph{3}, e0002051.
47 | #'
48 | #' Telesford, Q. K., Joyce, K. E., Hayasaka, S., Burdette, J. H., & Laurienti, P. J. (2011).
49 | #' The ubiquity of small-world networks.
50 | #' \emph{Brain Connectivity}, \emph{1}(5), 367-375.
51 | #'
52 | #' @author Alexander Christensen
53 | #'
54 | #' @export
55 | #Small-worldness Measure----
56 | smallworldness <- function (A, iter = 100, progBar = FALSE, method = c("HG","rand","TJHBL"))
57 | {
58 | if(missing(method))
59 | {method<-"TJHBL"
60 | }else{method<-match.arg(method)}
61 |
62 | mat<-matrix(0,nrow=nrow(A),ncol=ncol(A)) #Initialize bootstrap matrix
63 | asamps<-matrix(0,nrow=iter) #Initialize sample matrix
64 | csamps<-matrix(0,nrow=iter) #Initialize sample matrix
65 | if(progBar)
66 | {pb <- txtProgressBar(max=iter, style = 3)}
67 | for(i in 1:iter) #Generate array of bootstrapped samples
68 | {
69 | rand<-randnet(A = A)
70 | if(method=="TJHBL")
71 | {latt<-lattnet(ncol(A),sum(ifelse(A!=0,1,0))/2)}
72 | asamps[i,]<-pathlengths(rand)$ASPL
73 | if(method=="rand")
74 | {csamps[i,]<-clustcoeff(rand)$CC
75 | }else if(method=="HG"){csamps[i,]<-transitivity(rand)
76 | }else if(method=="TJHBL"){csamps[i,]<-clustcoeff(latt)$CC}else{stop("Method not available")}
77 | if(progBar)
78 | {setTxtProgressBar(pb, i)}
79 | }
80 | if(progBar)
81 | {close(pb)}
82 |
83 | nodes<-ncol(A)
84 | ASPL<-pathlengths(A)$ASPL
85 | CC<-clustcoeff(A)$CC
86 | trans<-transitivity(A)
87 | rASPL<-mean(asamps)
88 |
89 | if(method=="rand")
90 | {rCC<-mean(csamps)
91 | swm<-(CC/rCC)/(ASPL/rASPL)
92 | lrCCt<-rCC
93 | }else if(method=="HG")
94 | {rtrans<-mean(csamps)
95 | swm<-(trans/rtrans)/(ASPL/rASPL)
96 | lrCCt<-rtrans
97 | }else if(method=="TJHBL")
98 | {lCC<-mean(csamps)
99 | swm<-(rASPL/ASPL)-(CC/lCC)
100 | lrCCt<-lCC
101 | }
102 |
103 | return(list(swm=swm, rASPL=rASPL, lrCCt=lrCCt))
104 | }
105 | #----
--------------------------------------------------------------------------------
/R/strength.R:
--------------------------------------------------------------------------------
1 | #' Node Strength
2 | #' @description Computes strength of each node in a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param absolute Should network use absolute weights?
7 | #' Defaults to \code{TRUE}.
8 | #' Set to \code{FALSE} for signed weights
9 | #'
10 | #' @return A vector of strength values for each node in the network.
11 | #'
12 | #' If directed network, returns a list containing:
13 | #'
14 | #' \item{inStrength}{Strength of incoming edges (pointing to the node)}
15 | #'
16 | #' \item{outStrength}{Strength of outgoing edges (pointing away from the node)}
17 | #'
18 | #' \item{relInf}{Relative degree of incoming and outgoing edges.
19 | #' Positive values indicate more outgoing strength relative to incoming strength.
20 | #' Negative values indicate more incoming strength relative to outgoing strength}
21 | #'
22 | #' @examples
23 | #' # Pearson's correlation only for CRAN checks
24 | #' A <- TMFG(neoOpen, normal = FALSE)$A
25 | #'
26 | #' str <- strength(A)
27 | #'
28 | #' #Directed network
29 | #' \dontrun{
30 | #' dep <- depend(neoOpen)
31 | #'
32 | #' Adep <- TMFG(dep, depend = TRUE)$A
33 | #'
34 | #' str <- strength(Adep)
35 | #' }
36 | #'
37 | #' @references
38 | #' Rubinov, M., & Sporns, O. (2010).
39 | #' Complex network measures of brain connectivity: Uses and interpretations.
40 | #' \emph{NeuroImage}, \emph{52} 1059-1069.
41 | #'
42 | #' @author Alexander Christensen
43 | #'
44 | #' @export
45 | #Node Strength----
46 | strength <- function (A, absolute = TRUE)
47 | {
48 | if(is.vector(A))
49 | {return(0)
50 | }else if(nrow(A)!=ncol(A))
51 | {stop("Input not an adjacency matrix")}
52 |
53 | if(absolute)
54 | {A <- abs(A)}
55 | A <- as.matrix(A)
56 |
57 | if(isSymmetric(A, check.attributes = FALSE))
58 | {
59 | Str <- round(as.vector(colSums(A)),2)
60 | names(Str) <- colnames(A)
61 | return(Str)
62 | }else{
63 | #In-strength
64 | inStr <- as.vector(colSums(A))
65 | names(inStr) <- colnames(A)
66 | #Out-strength
67 | outStr <- as.vector(rowSums(A))
68 | names(outStr) <- colnames(A)
69 | #Relative influence
70 | relinf <- as.vector((outStr-inStr)/(outStr+inStr))
71 | names(relinf) <- colnames(A)
72 |
73 | if(all(relinf<.001))
74 | {Str <- round(as.vector(colSums(A)),2)
75 | names(Str) <- colnames(A)
76 | return(Str)
77 | }else{return(list(inStrength=inStr,outStrength=outStr,relInf=relinf))}
78 | }
79 | }
80 | #----
--------------------------------------------------------------------------------
/R/transitivity.R:
--------------------------------------------------------------------------------
1 | #' Transitivity
2 | #' @description Computes transitivity of a network
3 | #'
4 | #' @param A An adjacency matrix of network data
5 | #'
6 | #' @param weighted Is the network weighted?
7 | #' Defaults to \code{FALSE}.
8 | #' Set to \code{TRUE} for a weighted measure of transitivity
9 | #'
10 | #' @return Returns a value of transitivity
11 | #'
12 | #' @examples
13 | #' # Pearson's correlation only for CRAN checks
14 | #' A <- TMFG(neoOpen, normal = FALSE)$A
15 | #'
16 | #' trans <- transitivity(A, weighted=TRUE)
17 | #' @references
18 | #' Rubinov, M., & Sporns, O. (2010).
19 | #' Complex network measures of brain connectivity: Uses and interpretations.
20 | #' \emph{NeuroImage}, \emph{52}, 1059-1069.
21 | #'
22 | #' @author Alexander Christensen
23 | #'
24 | #' @export
25 | #Transitivity----
26 | transitivity <- function (A, weighted = FALSE)
27 | {
28 | if(!weighted)
29 | {
30 | A<-ifelse(A!=0,1,0)
31 | trans<-sum(diag(A%*%A%*%A))/((sum(A%*%A))-sum(diag(A%*%A)))
32 | }else if(weighted){
33 | K<-colSums(ifelse(A!=0,1,0))
34 | W<-A^(1/3)
35 | cyc<-diag(W%*%W%*%W)
36 | trans<-sum(cyc)/sum(K*(K-1))
37 | }
38 |
39 | return(trans)
40 | }
41 | #----
--------------------------------------------------------------------------------
/R/un.direct.R:
--------------------------------------------------------------------------------
1 | #' Convert Directed Network to Undirected Network
2 | #' @description Converts a directed network to an undirected network
3 | #'
4 | #' @param A Matrix or data frame.
5 | #' Adjacency matrix (network matrix)
6 | #'
7 | #' @param diagonal Numeric.
8 | #' Number to be placed on the diagonal.
9 | #' Defaults to \code{0}
10 | #'
11 | #' @return Returns a symmetric adjacency matrix
12 | #'
13 | #' @examples
14 | #' # Pearson's correlation only for CRAN checks
15 | #' A <- TMFG(neoOpen, normal = FALSE)$A
16 | #'
17 | #' # create a directed network
18 | #' dir <- A * sample(c(0,1), size = length(A), replace = TRUE)
19 | #'
20 | #' # undirect the directed network
21 | #' undir <- un.direct(dir)
22 | #'
23 | #' @author Alexander Christensen
24 | #'
25 | #' @export
26 | #Convert matrices to igraph format----
27 | un.direct <- function (A, diagonal = 0)
28 | {
29 | # turn network into matrix
30 | mat <- as.matrix(A)
31 |
32 | # check if already symmetric
33 | if(isSymmetric(mat))
34 | {
35 | message("Adjacency matrix is already symmetric")
36 | return(A)
37 | }
38 |
39 | # triangles
40 | lower <- mat[lower.tri(mat)]
41 | upper <- mat[upper.tri(mat)]
42 |
43 | # initialize symmetricize vector
44 | sym <- numeric(length(lower))
45 |
46 | # symmetricize
47 | sym[which(lower == upper)] <- lower[which(lower == upper)]
48 | sym[which(lower > upper)] <- lower[which(lower > upper)]
49 | sym[which(upper > lower)] <- upper[which(upper > lower)]
50 |
51 | # initialize new matrix
52 | mat2 <- matrix(0, nrow = nrow(A), ncol = ncol(A))
53 |
54 | # put in values
55 | mat2[lower.tri(mat2)] <- sym
56 | mat2 <- t(mat2) + mat2
57 |
58 | # check if symmetric
59 | if(isSymmetric(mat2))
60 | {
61 | row.names(mat2) <- colnames(A)
62 | colnames(mat2) <- colnames(A)
63 | diag(mat2) <- diagonal
64 | return(mat2)
65 | }else(stop("Adjacency matrix could not be made symmetric"))
66 | }
67 | #----
--------------------------------------------------------------------------------
/R/zzz.R:
--------------------------------------------------------------------------------
1 | .onload <- function(libname, pkgname)
2 | {library.dynam("NetworkToolbox",package=pkgname,lib.loc=libname)}
3 |
4 | .onAttach <- function(libname, pkgname)
5 | {
6 | temp <- packageDescription("NetworkToolbox")
7 | msg <- paste("Package: ",temp$Package,": ",temp$Title,"\n",
8 | "Version: ",temp$Version,"\n",
9 | "Updated on: ",
10 | temp$Date,"\n", sep="")
11 | msg <- paste(msg,"Maintainer: Alexander P. Christensen, University of North Carolina at Greensboro\n",sep="")
12 | msg <- paste(msg,"Contributors: Guido Previde Massara, University College London\n",sep="")
13 | msg <- paste(msg,'For citation information, type citation("NetworkToolbox")\n')
14 | msg <- paste(msg,'For vignettes, see \n')
15 | msg <- paste(msg,"For bugs and errors, submit an issue to ")
16 | packageStartupMessage(msg)
17 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### CRAN 1.4.2 | GitHub 1.4.3
2 |
3 | [](https://www.repostatus.org/#active)[](https://cran.r-project.org/package=NetworkToolbox) [](https://cran.r-project.org/package=NetworkToolbox)
4 |
5 | # How To Install
6 | ```
7 | if(!"devtools" %in% row.names(installed.packages())){
8 | install.packages("devtools")
9 | }
10 |
11 | devtools::install_github("AlexChristensen/NetworkToolbox")
12 | ```
13 |
14 | # NetworkToolbox
15 | Network analysis offers an intuitive perspective on complex phenomena via models depicted by nodes (variables) and edges (correlations). The ability of networks to model complexity has made them the standard approach for modeling the intricate interactions in the brain. Similarly, networks have become an increasingly attractive model for studying the complexity of psychological and psychopathological phenomena. NetworkToolbox aims to provide researchers with state-of-the-art methods and measures for estimating and analyzing brain, cognitive, and psychometric networks.
16 |
17 | # References
18 | Christensen, A. P. (2018). NetworkToolbox: Methods and measures for brain, cognitive, and
19 | psychometric network analysis in R. *The R Journal*, *10*, 422–439.
20 | https://doi.org/10.32614/RJ-2018-065
21 |
--------------------------------------------------------------------------------
/data/behavOpen.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexChristensen/NetworkToolbox/d41da6d7bbf6165d358ebf55470531c6c876c18c/data/behavOpen.RData
--------------------------------------------------------------------------------
/data/neoOpen.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexChristensen/NetworkToolbox/d41da6d7bbf6165d358ebf55470531c6c876c18c/data/neoOpen.rda
--------------------------------------------------------------------------------
/data/openness.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexChristensen/NetworkToolbox/d41da6d7bbf6165d358ebf55470531c6c876c18c/data/openness.RData
--------------------------------------------------------------------------------
/data/openness.key.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlexChristensen/NetworkToolbox/d41da6d7bbf6165d358ebf55470531c6c876c18c/data/openness.key.RData
--------------------------------------------------------------------------------
/inst/CITATION:
--------------------------------------------------------------------------------
1 | citHeader("To cite NetworkToolbox in publications use:")
2 |
3 | bibentry(
4 | bibtype = "article",
5 | key = "NetworkToolbox",
6 | title = "{NetworkToolbox}: Methods and measures for brain, cognitive, and psychometric network analysis in {R}",
7 | author = c(person("Christensen,", "Alexander")),
8 | journal = "The R Journal",
9 | pages = "422--439",
10 | year = "2018",
11 | doi = "10.32614/RJ-2018-065",
12 |
13 | textVersion =
14 | paste0("Christensen, A. P. (2018). ",
15 | "NetworkToolbox: Methods and measures for brain, cognitive, and psychometric network analysis in R. ",
16 | "The R Journal, 10, 422-439. https://doi.org/10.32614/RJ-2018-065")
17 | )
18 |
--------------------------------------------------------------------------------
/man/ECO.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ECO.R
3 | \name{ECO}
4 | \alias{ECO}
5 | \title{ECO Neural Network Filter}
6 | \usage{
7 | ECO(data, directed = FALSE)
8 | }
9 | \arguments{
10 | \item{data}{Can be a dataset or a correlation matrix}
11 |
12 | \item{directed}{Is the network directed?
13 | Defaults to \code{FALSE}.
14 | Set \code{TRUE} if the network is directed}
15 | }
16 | \value{
17 | A sparse association matrix
18 | }
19 | \description{
20 | Applies the ECO neural network filtering method
21 | }
22 | \examples{
23 | eco.net <- ECO(neoOpen)
24 |
25 | }
26 | \references{
27 | Fallani, F. D. V., Latora, V., & Chavez, M. (2017).
28 | A topological criterion for filtering information in complex brain networks.
29 | \emph{PLoS Computational Biology}, \emph{13}, e1005305.
30 | }
31 | \author{
32 | Alexander Christensen
33 | }
34 |
--------------------------------------------------------------------------------
/man/ECOplusMaST.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ECOplusMaST.R
3 | \name{ECOplusMaST}
4 | \alias{ECOplusMaST}
5 | \title{ECO+MaST Network Filter}
6 | \usage{
7 | ECOplusMaST(data)
8 | }
9 | \arguments{
10 | \item{data}{Can be a dataset or a correlation matrix}
11 | }
12 | \value{
13 | A sparse association matrix
14 | }
15 | \description{
16 | Applies the \code{\link[NetworkToolbox]{ECO}} neural network filtering method
17 | combined with the \code{\link[NetworkToolbox]{MaST}} filtering method
18 | }
19 | \examples{
20 | # half the variables for CRAN checks
21 | ECOplusMaST.net <- ECOplusMaST(neoOpen[,c(1:24)])
22 |
23 | }
24 | \references{
25 | Fallani, F. D. V., Latora, V., & Chavez, M. (2017).
26 | A topological criterion for filtering information in complex brain networks.
27 | \emph{PLoS Computational Biology}, \emph{13}, e1005305.
28 | }
29 | \author{
30 | Alexander Christensen
31 | }
32 |
--------------------------------------------------------------------------------
/man/LoGo.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/LoGo.R
3 | \name{LoGo}
4 | \alias{LoGo}
5 | \title{Local/Global Inversion Method}
6 | \usage{
7 | LoGo(
8 | data,
9 | cliques,
10 | separators,
11 | normal = TRUE,
12 | na.data = c("pairwise", "listwise", "fiml", "none"),
13 | partial = TRUE,
14 | ...
15 | )
16 | }
17 | \arguments{
18 | \item{data}{Must be a dataset}
19 |
20 | \item{cliques}{Cliques defined in the network.
21 | Input can be a list or matrix}
22 |
23 | \item{separators}{Separators defined in the network.
24 | Input can be a list or matrix}
25 |
26 | \item{normal}{Should data be transformed to a normal distribution?
27 | Defaults to \code{TRUE} (computes correlations using the \code{\link[qgraph]{cor_auto}} function).
28 | Set to \code{FALSE} for Pearson's correlations}
29 |
30 | \item{na.data}{How should missing data be handled?
31 | For \code{"listwise"} deletion the \code{\link{na.omit}} function is applied.
32 | Set to \code{"fiml"} for Full Information Maximum Likelihood (\code{\link[psych]{corFiml}}).
33 | Full Information Maximum Likelihood is \strong{recommended} but time consuming}
34 |
35 | \item{partial}{Should the output network's connections be the partial correlation between two nodes given all other nodes?
36 | Defaults to \code{TRUE}, which returns a partial correlation matrix.
37 | Set to \code{FALSE} for a sparse inverse covariance matrix}
38 |
39 | \item{...}{Additional arguments (deprecated arguments)}
40 | }
41 | \value{
42 | Returns the sparse LoGo-filtered inverse covariance matrix (\code{partial = FALSE})
43 | or LoGo-filtered partial correlation matrix (\code{partial = TRUE})
44 | }
45 | \description{
46 | Applies the Local/Global method to estimate
47 | a Gaussian Graphical Model (GGM) using a \code{\link[NetworkToolbox]{TMFG}}-filtered network
48 | (\strong{see and cite Barfuss et al., 2016}). Also used to
49 | convert clique and separator structure from
50 | \code{\link[NetworkToolbox]{MFCF}} into partial correlation
51 | and precision matrices
52 | }
53 | \examples{
54 | # normal set to FALSE for CRAN tests
55 | LoGonet <- LoGo(neoOpen, normal = FALSE, partial = TRUE)
56 |
57 | }
58 | \references{
59 | Barfuss, W., Massara, G. P., Di Matteo, T., & Aste, T. (2016).
60 | Parsimonious modeling with information filtering networks.
61 | \emph{Physical Review E}, \emph{94}, 062306.
62 | }
63 | \author{
64 | Alexander Christensen
65 | }
66 |
--------------------------------------------------------------------------------
/man/MFCF.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/MFCF.R
3 | \name{MFCF}
4 | \alias{MFCF}
5 | \title{Maximally Filtered Clique Forest}
6 | \usage{
7 | MFCF(
8 | data,
9 | cases = NULL,
10 | na.data = c("pairwise", "listwise", "fiml", "none"),
11 | time.series = FALSE,
12 | gain.fxn = c("logLik", "logLik.val", "rSquared.val"),
13 | min_size = 0,
14 | max_size = 8,
15 | pval = 0.05,
16 | pen = 0,
17 | drop_sep = FALSE,
18 | use_returns = FALSE
19 | )
20 | }
21 | \arguments{
22 | \item{data}{Matrix (n \code{x} n or p \code{x} n) or data frame.
23 | Can be a dataset or a correlation matrix}
24 |
25 | \item{cases}{Numeric. If \code{data} is a (partial) correlation
26 | matrix, then number of cases must be input.
27 | Defaults to \code{NULL}}
28 |
29 | \item{na.data}{Character.
30 | How should missing data be handled?
31 |
32 | \itemize{
33 |
34 | \item \code{"listwise"} --- Removes case if \strong{any} missing data exists. Applies \code{\link{na.omit}}
35 |
36 | \item \code{"pairwise"} --- Estimates correlations using the available data
37 | for each variable
38 |
39 | \item \code{"fiml"} --- Estimates correlations using the Full Information
40 | Maximum Likelihood. Recommended and most robust but time consuming
41 |
42 | \item \code{"none"} --- Default. No missing data or missing data has been
43 | handled by the user
44 |
45 | }}
46 |
47 | \item{time.series}{Boolean.
48 | Is \code{data} a time-series dataset?
49 | Defaults to \code{FALSE}.
50 | Set to \code{TRUE} to handle time-series data (n \code{x} p)}
51 |
52 | \item{gain.fxn}{Character.
53 | Gain function to be used for inclusion of nodes in cliques.
54 | There are several options available
55 | (see \code{\link[NetworkToolbox]{gain.functions}} for more details):
56 | \code{"logLik"}, \code{"logLik.val"}, \code{"rSquared.val"}.
57 | Defaults to \code{"rSquared.val"}}
58 |
59 | \item{min_size}{Numeric. Minimum number of nodes allowed per
60 | clique. Defaults to \code{0}}
61 |
62 | \item{max_size}{Numeric. Maximum number of nodes allowed per
63 | clique. Defaults to \code{8}}
64 |
65 | \item{pval}{Numeric. \emph{p}-value used to determine cut-offs for nodes
66 | to include in a clique}
67 |
68 | \item{pen}{Numeric. Multiplies the number of edges added to penalise
69 | complex models. Similar to the penalty term in AIC}
70 |
71 | \item{drop_sep}{Boolean. This parameter influences the MFCF only.
72 | Defaults to \code{FALSE}.
73 | If \code{TRUE}, then any separator can be used only once (similar
74 | to the \code{\link[NetworkToolbox]{TMFG}})}
75 |
76 | \item{use_returns}{Boolean. Only used in \code{"gain.fxn = rSquared.val"}.
77 | If set to \code{TRUE} the regression is
78 | performed on log-returns.
79 | Defaults to \code{FALSE}}
80 | }
81 | \value{
82 | Returns a list containing:
83 |
84 | \item{A}{MFCF filtered partial correlation network (adjacency matrix)}
85 |
86 | \item{J}{MFCF filtered inverse covariance matrix (precision matrix)}
87 |
88 | \item{cliques}{Cliques in the network
89 | (output for \code{\link[NetworkToolbox]{LoGo}})}
90 |
91 | \item{separators}{Separators in the network
92 | (output for \code{\link[NetworkToolbox]{LoGo}})}
93 | }
94 | \description{
95 | Applies the Maximally Filtered Clique Forest (MFCF) filtering method
96 | (\strong{Please see and cite Massara & Aste}).
97 | }
98 | \examples{
99 | # Load data
100 | data <- neoOpen
101 |
102 | \dontrun{
103 | # Use polychoric correlations and R-squared method
104 | MFCF.net <- MFCF(qgraph::cor_auto(data), cases = nrow(neoOpen))$A
105 |
106 | }
107 |
108 | }
109 | \references{
110 | Massara, G. P. & Aste, T. (2019).
111 | Learning clique forests.
112 | \emph{ArXiv}.
113 | }
114 | \author{
115 | Guido Previde Massara and Alexander Christensen
116 | }
117 |
--------------------------------------------------------------------------------
/man/MaST.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/MaST.R
3 | \name{MaST}
4 | \alias{MaST}
5 | \title{Maximum Spanning Tree}
6 | \usage{
7 | MaST(
8 | data,
9 | normal = TRUE,
10 | na.data = c("pairwise", "listwise", "fiml", "none"),
11 | depend = FALSE
12 | )
13 | }
14 | \arguments{
15 | \item{data}{Can be a dataset or a correlation matrix}
16 |
17 | \item{normal}{Should data be transformed to a normal distribution?
18 | Input must be a dataset.
19 | Defaults to \code{TRUE}.
20 | Computes correlations using the \code{\link[qgraph]{cor_auto}} function.
21 | Set to \code{FALSE} for Pearson's correlation}
22 |
23 | \item{na.data}{How should missing data be handled?
24 | For \code{"listwise"} deletion the \code{\link{na.omit}} function is applied.
25 | Set to \code{"fiml"} for Full Information Maximum Likelihood (\code{\link[psych]{corFiml}}).
26 | Full Information Maximum Likelihood is \strong{recommended} but time consuming}
27 |
28 | \item{depend}{Is network a dependency (or directed) network?
29 | Defaults to \code{FALSE}.
30 | Set \code{TRUE} to generate a MaST-filtered dependency network
31 | (output obtained from the \code{\link{depend}} function)}
32 | }
33 | \value{
34 | A sparse association matrix
35 | }
36 | \description{
37 | Applies the Maximum Spanning Tree (MaST) filtering method
38 | }
39 | \examples{
40 | # Pearson's correlation only for CRAN checks
41 | MaST.net <- MaST(neoOpen, normal = FALSE)
42 |
43 | }
44 | \author{
45 | Alexander Christensen
46 | }
47 |
--------------------------------------------------------------------------------
/man/NetworkToolbox-package.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/NetworkToolbox.R
3 | \docType{package}
4 | \name{NetworkToolbox-package}
5 | \alias{NetworkToolbox}
6 | \alias{NetworkToolbox-package}
7 | \title{NetworkToolbox--package}
8 | \description{
9 | Implements network analysis and graph theory measures used
10 | in neuroscience, cognitive science, and psychology.
11 | Methods include various filtering methods and approaches such as
12 | threshold, dependency, Information Filtering Networks, and Efficiency-Cost Optimization.
13 | Brain methods include the recently developed Connectome Predictive Modeling.
14 | Also implements several network measures including local network characteristics
15 | (e.g., centrality), global network characteristics (e.g., clustering coefficient),
16 | and various other measures associated with the reliability and
17 | reproducibility of network analysis.
18 | }
19 | \references{
20 | Christensen, A. P. (in press).
21 | NetworkToolbox: Methods and measures for brain, cognitive, and psychometric network analysis in R.
22 | \emph{The R Journal}, \emph{10}, 422-439.
23 | }
24 | \author{
25 | Alexander Christensen
26 | }
27 |
--------------------------------------------------------------------------------
/man/adapt.a.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/adapt.a.R
3 | \name{adapt.a}
4 | \alias{adapt.a}
5 | \title{Adaptive Alpha}
6 | \usage{
7 | adapt.a(
8 | test = c("anova", "chisq", "cor", "one.sample", "two.sample", "paired"),
9 | ref.n = NULL,
10 | n = NULL,
11 | alpha = 0.05,
12 | power = 0.8,
13 | efxize = c("small", "medium", "large"),
14 | groups = NULL,
15 | df = NULL
16 | )
17 | }
18 | \arguments{
19 | \item{test}{Type of statistical test being used.
20 | Can be any of the tests listed}
21 |
22 | \item{ref.n}{\emph{n0} in the above equation.
23 | Reference sample size.
24 | If sample size was determined a priori, then the reference
25 | number of participants can be set. This removes the calculation of sample
26 | size based on power}
27 |
28 | \item{n}{\emph{n*} in the above equation.
29 | Number of participants in the experiment sample (or per group)}
30 |
31 | \item{alpha}{\eqn{\alpha} in the above equation.
32 | Alpha value to adjust.
33 | Defaults to \code{.05}}
34 |
35 | \item{power}{Power (\eqn{1 - \beta}) value.
36 | Used to estimate the reference sample size (n0).
37 | Defaults to \code{.80}}
38 |
39 | \item{efxize}{Effect size to be used to estimate the reference sample size.
40 | Effect sizes are based on Cohen (1992).
41 | Numeric values can be used.
42 | Defaults to \code{"medium"}}
43 |
44 | \item{groups}{Number of groups (only for \code{test = "anova"})}
45 |
46 | \item{df}{Number of degrees of freedom (only for \code{test = "chisq"})}
47 | }
48 | \value{
49 | A list containing the following objects:
50 |
51 | \item{adapt.a}{The adapted alpha value}
52 |
53 | \item{crit.value}{The critical value associated with the adapted alpha value}
54 |
55 | \item{orig.a}{The original alpha value}
56 |
57 | \item{ref.n}{The reference sample size based on alpha, power, effect size, and test}
58 |
59 | \item{exp.n}{The sample size of the experimental sample}
60 |
61 | \item{power}{The power used to determine the reference sample size}
62 |
63 | \item{test}{The type of statistical test used}
64 | }
65 | \description{
66 | Compute an alpha value adjusted for sample size. The adjusted value is based on
67 | Perez and Pericchi's (2014) formula (equation 11, see below) using a reference sample, which can be
68 | defined a priori or estimated using the sample size calculation from power.
69 |
70 | \deqn{\frac{\alpha * \sqrt{n_0 \times (log(n_0) + \chi^{2}_{\alpha}(1))}}{\sqrt{n^* \times (log(n^*) + \chi^{2}_{\alpha}(1))}}}{\alpha * \sqrt(n0 times (log(n0) + \chi^2_\alpha(1))) / \sqrt(n* times (log(n*) + \chi^2_\alpha(1)))}
71 | }
72 | \examples{
73 | #ANOVA
74 | adapt.anova <- adapt.a(test = "anova", n = 200, alpha = .05, power = .80, groups = 3)
75 |
76 | #Chi-square
77 | adapt.chisq <- adapt.a(test = "chisq", n = 200, alpha = .05, power = .80, df = 3)
78 |
79 | #Correlation
80 | adapt.cor <- adapt.a(test = "cor", n = 200, alpha = .05, power = .80)
81 |
82 | #One-sample t-test
83 | adapt.one <- adapt.a(test = "one.sample", n = 200, alpha = .05, power = .80)
84 |
85 | #Two-sample t-test
86 | adapt.two <- adapt.a(test = "two.sample", n = 200, alpha = .05, power = .80)
87 |
88 | #Paired sample t-test
89 | adapt.paired <- adapt.a(test = "paired", n = 200, alpha = .05, power = .80, efxize = "medium")
90 |
91 | }
92 | \references{
93 | Cohen, J. (1992).
94 | A power primer.
95 | \emph{Psychological Bulletin}, \emph{112}, 155-159.
96 |
97 | Perez, M. E., & Pericchi, L. R. (2014).
98 | Changing statistical significance with the amount of information: The adaptive \emph{a} significance level.
99 | \emph{Statistics & Probability Letters}, \emph{85}, 20-24.
100 | }
101 | \author{
102 | Alexander Christensen
103 | }
104 |
--------------------------------------------------------------------------------
/man/behavOpen.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/behavOpen.R
3 | \docType{data}
4 | \name{behavOpen}
5 | \alias{behavOpen}
6 | \title{NEO-PI-3 for Resting-state Data}
7 | \format{
8 | behavOpen (vector, length = 144)
9 | }
10 | \usage{
11 | data(behavOpen)
12 | }
13 | \description{
14 | NEO-PI-3 Openness to Experience associated with resting-state data (\emph{n} = 144).
15 | }
16 | \details{
17 | Behavioral data of NEO-PI-3 associated with each connectivity matrix (open).
18 |
19 | To access the resting-state brain data, please go to \url{https://drive.google.com/file/d/1T7_mComB6HPxJxZZwwsLLSYHXsOuvOBt/view?usp=sharing}
20 | }
21 | \examples{
22 | data("behavOpen")
23 | }
24 | \references{
25 | Beaty, R. E., Chen, Q., Christensen, A. P., Qiu, J., Silvia, P. J., & Schacter, D. L. (2018).
26 | Brain networks of the imaginative mind: Dynamic functional connectivity of default and cognitive control networks relates to Openness to Experience.
27 | \emph{Human Brain Mapping}, \emph{39}, 811-821.
28 |
29 | Beaty, R. E., Kenett, Y. N., Christensen, A. P., Rosenberg, M. D., Benedek, M., Chen, Q., ... & Silvia, P. J. (2018).
30 | Robust prediction of individual creative ability from brain functional connectivity.
31 | \emph{Proceedings of the National Academy of Sciences}, 201713532.
32 | }
33 | \keyword{datasets}
34 |
--------------------------------------------------------------------------------
/man/betweenness.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/betweenness.R
3 | \name{betweenness}
4 | \alias{betweenness}
5 | \title{Betweenness Centrality}
6 | \usage{
7 | betweenness(A, weighted = TRUE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{TRUE}.
14 | Set to \code{FALSE} for unweighted measure of betweenness centrality}
15 | }
16 | \value{
17 | A vector of betweenness centrality values for each node in the network
18 | }
19 | \description{
20 | Computes betweenness centrality of each node in a network
21 | }
22 | \examples{
23 | # Pearson's correlation only for CRAN checks
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | #Weighted BC
27 | BCw <- betweenness(A)
28 |
29 | #Unweighted BC
30 | BC <- betweenness(A, weighted = FALSE)
31 |
32 | }
33 | \references{
34 | Rubinov, M., & Sporns, O. (2010).
35 | Complex network measures of brain connectivity: Uses and interpretations.
36 | \emph{NeuroImage}, \emph{52}, 1059-1069.
37 | }
38 | \author{
39 | Alexander Christensen
40 | }
41 |
--------------------------------------------------------------------------------
/man/binarize.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/binarize.R
3 | \name{binarize}
4 | \alias{binarize}
5 | \title{Binarize Network}
6 | \usage{
7 | binarize(A)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data (or an array of matrices)}
11 | }
12 | \value{
13 | Returns an adjacency matrix of 1's and 0's
14 | }
15 | \description{
16 | Converts weighted adjacency matrix to a binarized adjacency matrix
17 | }
18 | \examples{
19 | # Pearson's correlation only for CRAN checks
20 | A <- TMFG(neoOpen, normal = FALSE)$A
21 |
22 | neoB <- binarize(A)
23 |
24 | }
25 | \author{
26 | Alexander Christensen
27 | }
28 |
--------------------------------------------------------------------------------
/man/closeness.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/closeness.R
3 | \name{closeness}
4 | \alias{closeness}
5 | \title{Closeness Centrality}
6 | \usage{
7 | closeness(A, weighted = TRUE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{TRUE}.
14 | Set to \code{FALSE} for unweighted measure of closeness centrality}
15 | }
16 | \value{
17 | A vector of closeness centrality values for each node in the network
18 | }
19 | \description{
20 | Computes closeness centrality of each node in a network
21 | }
22 | \examples{
23 | # Pearson's correlation only for CRAN checks
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | #Weighted LC
27 | LC <- closeness(A)
28 |
29 | #Unweighted LC
30 | LC <- closeness(A, weighted = FALSE)
31 |
32 | }
33 | \references{
34 | Rubinov, M., & Sporns, O. (2010).
35 | Complex network measures of brain connectivity: Uses and interpretations.
36 | \emph{NeuroImage}, \emph{52}, 1059-1069.
37 | }
38 | \author{
39 | Alexander Christensen
40 | }
41 |
--------------------------------------------------------------------------------
/man/clustcoeff.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/clustcoeff.R
3 | \name{clustcoeff}
4 | \alias{clustcoeff}
5 | \title{Clustering Coefficient}
6 | \usage{
7 | clustcoeff(A, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{FALSE}.
14 | Set to \code{TRUE} for weighted measures of CC and CCi}
15 | }
16 | \value{
17 | Returns a list containing:
18 |
19 | \item{CC}{Global clustering coefficient. The average clustering coefficient for each node in the network}
20 |
21 | \item{CCi}{Local clustering coefficient. The clustering coefficient for each node in the network}
22 | }
23 | \description{
24 | Computes global clustering coefficient (CC) and local clustering coefficient (CCi)
25 | }
26 | \examples{
27 | # Pearson's correlation only for CRAN checks
28 | A <- TMFG(neoOpen, normal = FALSE)$A
29 |
30 | #Unweighted CC
31 | CCu <- clustcoeff(A)
32 |
33 | #Weighted CC
34 | CCw <- clustcoeff(A, weighted=TRUE)
35 |
36 | }
37 | \references{
38 | Rubinov, M., & Sporns, O. (2010).
39 | Complex network measures of brain connectivity: Uses and interpretations.
40 | \emph{NeuroImage}, \emph{52}, 1059-1069.
41 | }
42 | \author{
43 | Alexander Christensen
44 | }
45 |
--------------------------------------------------------------------------------
/man/comcat.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/comcat.R
3 | \name{comcat}
4 | \alias{comcat}
5 | \title{Communicating Nodes}
6 | \usage{
7 | comcat(
8 | A,
9 | comm = c("walktrap", "louvain"),
10 | cent = c("strength", "degree"),
11 | absolute = TRUE,
12 | metric = c("across", "each"),
13 | diagonal = 0,
14 | ...
15 | )
16 | }
17 | \arguments{
18 | \item{A}{An adjacency matrix of network data}
19 |
20 | \item{comm}{Can be a vector of community assignments or community detection algorithms
21 | (\code{"walktrap"} or \code{"louvain"}) can be used to determine the number of factors.
22 | Defaults to \code{"walktrap"}.
23 | Set to \code{"louvain"} for \code{\link[NetworkToolbox]{louvain}} community detection}
24 |
25 | \item{cent}{Centrality measure to be used.
26 | Defaults to \code{"strength"}.}
27 |
28 | \item{absolute}{Should network use absolute weights?
29 | Defaults to \code{TRUE}.
30 | Set to \code{FALSE} for signed weights}
31 |
32 | \item{metric}{Whether the metric should be compute for across all of the communities
33 | (a single value) or for each community (a value for each community).
34 | Defaults to \code{"across"}.
35 | Set to \code{"each"} for values for each community}
36 |
37 | \item{diagonal}{Sets the diagonal values of the \code{A} input.
38 | Defaults to \code{0}}
39 |
40 | \item{...}{Additional arguments for \code{\link[igraph]{cluster_walktrap}}
41 | and \code{\link[NetworkToolbox]{louvain}} community detection algorithms}
42 | }
43 | \value{
44 | A vector containing the between-community strength value for each node
45 | }
46 | \description{
47 | Computes the between-community strength for each node in the network
48 | }
49 | \examples{
50 | # Pearson's correlation only for CRAN checks
51 | A <- TMFG(neoOpen, normal = FALSE)$A
52 |
53 | communicating <- comcat(A, comm = "walktrap", cent = "strength", metric = "across")
54 |
55 | }
56 | \references{
57 | Blanken, T. F., Deserno, M. K., Dalege, J., Borsboom, D., Blanken, P., Kerkhof, G. A., & Cramer, A. O. (2018).
58 | The role of stabilizing and communicating symptoms given overlapping communities in psychopathology networks.
59 | \emph{Scientific Reports}, \emph{8}, 5854.
60 | }
61 | \author{
62 | Alexander Christensen
63 | }
64 |
--------------------------------------------------------------------------------
/man/comm.close.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/comm.close.R
3 | \name{comm.close}
4 | \alias{comm.close}
5 | \title{Community Closeness Centrality}
6 | \usage{
7 | comm.close(A, comm, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{comm}{A vector or matrix corresponding to the
13 | community each node belongs to}
14 |
15 | \item{weighted}{Is the network weighted?
16 | Defaults to \code{FALSE}.
17 | Set to \code{TRUE} for weighted measures}
18 | }
19 | \value{
20 | A vector of community closeness centrality values for each specified
21 | community in the network
22 | (larger values suggest more central positioning)
23 | }
24 | \description{
25 | Computes the community closeness centrality measure of each
26 | community in a network
27 | }
28 | \examples{
29 | # Pearson's correlation only for CRAN checks
30 | A <- TMFG(neoOpen, normal = FALSE)$A
31 |
32 | comm <- igraph::walktrap.community(convert2igraph(abs(A)))$membership
33 |
34 | #Weighted
35 | result <- comm.close(A, comm)
36 |
37 | #Unweighted
38 | result <- comm.close(A, comm, weighted = FALSE)
39 |
40 | }
41 | \references{
42 | Christensen, A. P. (in press).
43 | NetworkToolbox: Methods and measures for brain, cognitive, and psychometric network analysis in R.
44 | \emph{The R Journal}, \emph{10}, 422-439.
45 | }
46 | \author{
47 | Alexander Christensen
48 | }
49 |
--------------------------------------------------------------------------------
/man/comm.eigen.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/comm.eigen.R
3 | \name{comm.eigen}
4 | \alias{comm.eigen}
5 | \title{Community Eigenvector Centrality}
6 | \usage{
7 | comm.eigen(A, comm, weighted = TRUE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix}
11 |
12 | \item{comm}{A vector or matrix corresponding to the
13 | community each node belongs to}
14 |
15 | \item{weighted}{Is the network weighted?
16 | Defaults to \code{TRUE}.
17 | Set to \code{FALSE} for weighted measures}
18 | }
19 | \value{
20 | A vector of community eigenvector centrality values for
21 | each specified community in the network
22 | (larger values suggest more central positioning)
23 | }
24 | \description{
25 | Computes the \link[NetworkToolbox]{flow.frac} for each
26 | community in the network. The values are equivalent to the community's
27 | eigenvector centrality
28 | }
29 | \examples{
30 | # Pearson's correlation only for CRAN checks
31 | A <- TMFG(neoOpen, normal = FALSE)$A
32 |
33 | comm <- igraph::walktrap.community(convert2igraph(abs(A)))$membership
34 |
35 | result <- comm.eigen(A, comm)
36 |
37 | }
38 | \references{
39 | Giscard, P. L., & Wilson, R. C. (2018).
40 | A centrality measure for cycles and subgraphs II.
41 | \emph{Applied Network Science}, \emph{3}, 9.
42 | }
43 | \author{
44 | Alexander Christensen
45 | }
46 |
--------------------------------------------------------------------------------
/man/comm.str.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/comm.str.R
3 | \name{comm.str}
4 | \alias{comm.str}
5 | \title{Community Strength/Degree Centrality}
6 | \usage{
7 | comm.str(A, comm, weighted = TRUE, measure = c("within", "between"))
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{comm}{A vector corresponding to the
13 | community each node belongs to}
14 |
15 | \item{weighted}{Is the network weighted?
16 | Defaults to \code{TRUE}.
17 | Set to \code{FALSE} for weighted measures}
18 |
19 | \item{measure}{Type of measure to compute:
20 |
21 | \itemize{
22 |
23 | \item \code{"within"} --- Computes the community strength or degree of nodes within its own community
24 |
25 | \item \code{"between"} --- Computes the community strength or degree of nodes outside of its own community
26 |
27 | }}
28 | }
29 | \value{
30 | A vector of community strength/degree centrality values for each specified
31 | community in the network
32 | (larger values suggest more central positioning)
33 | }
34 | \description{
35 | Computes the community
36 | \code{\link[NetworkToolbox]{strength}}/\code{\link[NetworkToolbox]{degree}}
37 | centrality measure of each community in a network or computes the
38 | \code{\link[NetworkToolbox]{strength}}/\code{\link[NetworkToolbox]{degree}}
39 | centrality measure of each community's connections to the other communities
40 | }
41 | \examples{
42 | # Pearson's correlation only for CRAN checks
43 | A <- TMFG(neoOpen, normal = FALSE)$A
44 |
45 | comm <- igraph::walktrap.community(convert2igraph(abs(A)))$membership
46 |
47 | #Strength
48 | within.ns <- comm.str(A, comm, measure = "within")
49 | between.ns <- comm.str(A, comm, measure = "between")
50 |
51 | #Degree
52 | within.deg <- comm.str(A, comm, weighted = FALSE, measure = "within")
53 | between.deg <- comm.str(A, comm, weighted = FALSE, measure = "between")
54 |
55 | }
56 | \author{
57 | Alexander Christensen
58 | }
59 |
--------------------------------------------------------------------------------
/man/conn.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/conn.R
3 | \name{conn}
4 | \alias{conn}
5 | \title{Network Connectivity}
6 | \usage{
7 | conn(A)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of a network}
11 | }
12 | \value{
13 | Returns a list containing:
14 |
15 | \item{weights}{Each edge weight in the network}
16 |
17 | \item{mean}{The mean of the edge weights in the network}
18 |
19 | \item{sd}{The standard deviation of the edge weights in the network}
20 |
21 | \item{total}{The sum total of the edge weights in the network}
22 | }
23 | \description{
24 | Computes the average and standard deviation of the weights in the network
25 | }
26 | \examples{
27 | # Pearson's correlation only for CRAN checks
28 | A <- TMFG(neoOpen, normal = FALSE)$A
29 |
30 | connectivity <- conn(A)
31 |
32 | }
33 | \author{
34 | Alexander Christensen
35 | }
36 |
--------------------------------------------------------------------------------
/man/convert2igraph.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/convert2igraph.R
3 | \name{convert2igraph}
4 | \alias{convert2igraph}
5 | \title{Convert Network(s) to igraph's Format}
6 | \usage{
7 | convert2igraph(A, neural = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{Adjacency matrix (network matrix) or brain connectivity array
11 | (from \code{\link[NetworkToolbox]{convertConnBrainMat}})}
12 |
13 | \item{neural}{Is input a brain connectivity array (i.e., m x m x n)?
14 | Defaults to \code{FALSE}.
15 | Set to \code{TRUE} to convert each brain connectivity matrix}
16 | }
17 | \value{
18 | Returns a network matrix in \code{igraph}'s format or
19 | returns a list of brain connectivity matrices each of which have been
20 | convert to \code{igraph}'s format
21 | }
22 | \description{
23 | Converts single or multiple networks into \code{igraph}'s format for network analysis
24 | }
25 | \examples{
26 | # Pearson's correlation only for CRAN checks
27 | A <- TMFG(neoOpen, normal = FALSE)$A
28 |
29 | igraphNetwork <- convert2igraph(A)
30 |
31 | \dontrun{
32 | neuralarray <- convertConnBrainMat()
33 |
34 | igraphNeuralList <- convert2igraph(neuralarray, neural = TRUE)
35 | }
36 |
37 | }
38 | \author{
39 | Alexander Christensen
40 | }
41 |
--------------------------------------------------------------------------------
/man/convertConnBrainMat.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/convertConnBrainMat.R
3 | \name{convertConnBrainMat}
4 | \alias{convertConnBrainMat}
5 | \title{Import CONN Toolbox Brain Matrices to R format}
6 | \usage{
7 | convertConnBrainMat(MatlabData, progBar = TRUE)
8 | }
9 | \arguments{
10 | \item{MatlabData}{Input for Matlab data file.
11 | Defaults to interactive file choice}
12 |
13 | \item{progBar}{Should progress bar be displayed?
14 | Defaults to \code{TRUE}.
15 | Set \code{FALSE} for no progress bar}
16 | }
17 | \value{
18 | Returns a list containing:
19 |
20 | \item{rmat}{Correlation matrices for each participant (m) in an array (n x n x m)}
21 |
22 | \item{zmat}{Z-score matrices for each participant (m) in an array (n x n x m)}
23 | }
24 | \description{
25 | Converts a Matlab brain z-score connectivity array (n x n x m)
26 | where \strong{n} is the n x n connectivity matrices and \strong{m} is the participant.
27 | If you would like to simply import a connectivity array from Matlab, then see the examples
28 | }
29 | \examples{
30 | \dontrun{
31 | neuralarray <- convertConnBrainMat()
32 |
33 | #Import correlation connectivity array from Matlab
34 | library(R.matlab)
35 | neuralarray<-readMat(file.choose())
36 | }
37 |
38 | }
39 | \author{
40 | Alexander Christensen
41 | }
42 |
--------------------------------------------------------------------------------
/man/cor2cov.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/cor2cov.R
3 | \name{cor2cov}
4 | \alias{cor2cov}
5 | \title{Convert Correlation Matrix to Covariance Matrix}
6 | \usage{
7 | cor2cov(cormat, data)
8 | }
9 | \arguments{
10 | \item{cormat}{A correlation matrix}
11 |
12 | \item{data}{The dataset the correlation matrix is from}
13 | }
14 | \value{
15 | Returns a covariance matrix
16 | }
17 | \description{
18 | Converts a correlation matrix to a covariance matrix
19 | }
20 | \examples{
21 | cormat <- cor(neoOpen)
22 |
23 | covmat <- cor2cov(cormat,neoOpen)
24 |
25 | }
26 | \author{
27 | Alexander Christensen
28 | }
29 |
--------------------------------------------------------------------------------
/man/core.items.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/core.items.R
3 | \name{core.items}
4 | \alias{core.items}
5 | \title{Core Items}
6 | \usage{
7 | core.items(A, comm, by = c("network", "communities"))
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{comm}{A vector or matrix corresponding to the community each node belongs to}
13 |
14 | \item{by}{Should the core items be defined by network or communities?
15 | Defaults to \code{"network"}.
16 | Set to \code{"communities"} to define core items within communities}
17 | }
18 | \value{
19 | Returns a list containing:
20 |
21 | \item{core}{Core items for each community}
22 |
23 | \item{inter}{Intermediate items for each community}
24 |
25 | \item{peri}{Peripheral items for each community}
26 | }
27 | \description{
28 | Automatically determines core, intermediary, and peripheral items in the network.
29 | The entire network or within-community gradations can be determined. Based on the
30 | \code{\link[NetworkToolbox]{hybrid}} centrality
31 | }
32 | \examples{
33 | #network
34 | # Pearson's correlation only for CRAN checks
35 | A <- TMFG(neoOpen, normal = FALSE)$A
36 |
37 | #core items by network
38 | coreBYnetwork <- core.items(A, by = "network")
39 |
40 | #theoretical factors
41 | comm <- c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8))
42 |
43 | #core items by communities
44 | coreBYcomm <- core.items(A, comm, by = "communities")
45 |
46 | }
47 | \author{
48 | Alexander Christensen
49 | }
50 |
--------------------------------------------------------------------------------
/man/dCor.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/dCor.R
3 | \name{dCor}
4 | \alias{dCor}
5 | \title{Distance Correlation for ROI Time Series}
6 | \usage{
7 | dCor(neurallist, centering = c("U", "double"))
8 | }
9 | \arguments{
10 | \item{neurallist}{List.
11 | A time series list from \code{\link[NetworkToolbox]{convertConnBrainMat}} function}
12 |
13 | \item{centering}{Character.
14 | Options for centering the Euclidean distances.
15 |
16 | \itemize{
17 | \item \code{"U"} --- Uses number of time points minus 2 in the computation of the mean
18 |
19 | \item \code{"double"} --- Uses the mean
20 |
21 | }}
22 | }
23 | \value{
24 | Returns a \emph{m} x \emph{m} matrix corresponding to distance correlations
25 | between ROIs
26 | }
27 | \description{
28 | Computes the distance correlation (Yoo et al., 2019) for
29 | ROI time series data. This function is mainly a subroutine for the
30 | \code{\link[NetworkToolbox]{dCor.parallel}} function
31 | }
32 | \examples{
33 | \dontrun{
34 | # Import time series data
35 | neurallist <- convertConnBrainMat()
36 |
37 | # Run distance correlation
38 | dCor(neurallist)
39 |
40 | }
41 |
42 | }
43 | \references{
44 | Yoo, K., Rosenberg, M. D., Noble, S., Scheinost, D., Constable, R. T., & Chun, M. M. (2019).
45 | Multivariate approaches improve the reliability and validity of functional connectivity and prediction of individual behaviors.
46 | \emph{NeuroImage}, \emph{197}, 212-223.
47 | }
48 | \author{
49 | Alexander Christensen
50 | }
51 |
--------------------------------------------------------------------------------
/man/dCor.parallel.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/dCor.parallel.R
3 | \name{dCor.parallel}
4 | \alias{dCor.parallel}
5 | \title{Parallelization of Distance Correlation for ROI Time Series}
6 | \usage{
7 | dCor.parallel(neurallist, cores)
8 | }
9 | \arguments{
10 | \item{neurallist}{List of lists.
11 | A list containing the time series list from all participants imported from the
12 | \code{\link[NetworkToolbox]{convertConnBrainMat}} function}
13 |
14 | \item{cores}{Number of computer processing cores to use when performing covariate analyses.
15 | Defaults to \emph{n} - 1 total number of cores.
16 | Set to any number between 1 and maximum amount of cores on your computer}
17 | }
18 | \value{
19 | Returns a \emph{m} x \emph{m} x \emph{n} array corresponding to distance correlations
20 | between ROIs (\emph{m} x \emph{m} matrix) for \emph{n} participants
21 | }
22 | \description{
23 | Parallelizes the \code{\link[NetworkToolbox]{dCor}} function
24 | for faster computation times
25 | }
26 | \examples{
27 | \dontrun{
28 | # Import time series data
29 | for(i in 1:5)
30 |
31 | # Run distance correlation
32 | dCor.parallel(mat.list, cores = 2)
33 |
34 | }
35 |
36 | }
37 | \references{
38 | Yoo, K., Rosenberg, M. D., Noble, S., Scheinost, D., Constable, R. T., & Chun, M. M. (2019).
39 | Multivariate approaches improve the reliability and validity of functional connectivity and prediction of individual behaviors.
40 | \emph{NeuroImage}, \emph{197}, 212-223.
41 | }
42 | \author{
43 | Alexander Christensen
44 | }
45 |
--------------------------------------------------------------------------------
/man/degree.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/degree.R
3 | \name{degree}
4 | \alias{degree}
5 | \title{Degree}
6 | \usage{
7 | degree(A)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 | }
12 | \value{
13 | A vector of degree values for each node in the network.
14 |
15 | If directed network, returns a list containing:
16 |
17 | \item{inDegree}{Degree of incoming edges (pointing to the node)}
18 |
19 | \item{outDegree}{Degree of outgoing edges (pointing away from the node)}
20 |
21 | \item{relInf}{Relative degree of incoming and outgoing edges.
22 | Positive values indicate more outgoing degree relative to incoming degree.
23 | Negative values indicate more incoming degree relative to outgoing degree}
24 | }
25 | \description{
26 | Computes degree of each node in a network
27 | }
28 | \examples{
29 | #Undirected network
30 | ## Pearson's correlation only for CRAN checks
31 | A <- TMFG(neoOpen, normal = FALSE)$A
32 |
33 | deg <- degree(A)
34 |
35 | #Directed network
36 | \dontrun{
37 | dep <- depend(neoOpen)
38 |
39 | Adep <- TMFG(dep, depend = TRUE)$A
40 |
41 | deg <- degree(Adep)
42 | }
43 |
44 | }
45 | \references{
46 | Rubinov, M., & Sporns, O. (2010).
47 | Complex network measures of brain connectivity: Uses and interpretations.
48 | \emph{NeuroImage}, \emph{52}, 1059-1069.
49 | }
50 | \author{
51 | Alexander Christensen
52 | }
53 |
--------------------------------------------------------------------------------
/man/depend.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/depend.R
3 | \name{depend}
4 | \alias{depend}
5 | \title{Dependency Network Approach}
6 | \usage{
7 | depend(
8 | data,
9 | normal = FALSE,
10 | na.data = c("pairwise", "listwise", "fiml", "none"),
11 | index = FALSE,
12 | fisher = FALSE,
13 | progBar = TRUE
14 | )
15 | }
16 | \arguments{
17 | \item{data}{A set of data}
18 |
19 | \item{normal}{Should data be transformed to a normal distribution?
20 | Defaults to \code{FALSE}. Data is not transformed to be normal.
21 | Set to \code{TRUE} if data should be transformed to be normal
22 | (computes correlations using the \link[qgraph]{cor_auto} function)}
23 |
24 | \item{na.data}{How should missing data be handled?
25 | For \code{"listwise"} deletion the \code{\link{na.omit}} function is applied.
26 | Set to \code{"fiml"} for Full Information Maximum Likelihood (\link[psych]{corFiml}).
27 | Full Information Maximum Likelihood is \strong{recommended} but time consuming}
28 |
29 | \item{index}{Should correlation with the latent variable
30 | (i.e., weighted average of all variables) be removed?
31 | Defaults to \code{FALSE}.
32 | Set to \code{TRUE} to remove common latent factor}
33 |
34 | \item{fisher}{Should Fisher's Z-test be used to keep significantly higher influences (index only)?
35 | Defaults to \code{FALSE}.
36 | Set to \code{TRUE} to remove non-significant influences}
37 |
38 | \item{progBar}{Should progress bar be displayed?
39 | Defaults to \code{TRUE}.
40 | Set to \code{FALSE} for no progress bar}
41 | }
42 | \value{
43 | Returns an adjacency matrix of dependencies
44 | }
45 | \description{
46 | Generates a dependency matrix of the data (index argument is still in testing phase)
47 | }
48 | \examples{
49 | \dontrun{
50 | D <- depend(neoOpen)
51 |
52 | Dindex <- depend(neoOpen, index = TRUE)
53 | }
54 | }
55 | \references{
56 | Kenett, D. Y., Tumminello, M., Madi, A., Gur-Gershgoren, G., Mantegna, R. N., & Ben-Jacob, E. (2010).
57 | Dominating clasp of the financial sector revealed by partial correlation analysis of the stock market.
58 | \emph{PLoS one}, \emph{5}, e15032.
59 |
60 | Kenett, D. Y., Huang, X., Vodenska, I., Havlin, S., & Stanley, H. E. (2015).
61 | Partial correlation analysis: Applications for financial markets.
62 | \emph{Quantitative Finance}, \emph{15}, 569-578.
63 | }
64 | \author{
65 | Alexander Christensen
66 | }
67 |
--------------------------------------------------------------------------------
/man/depna.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/depna.R
3 | \name{depna}
4 | \alias{depna}
5 | \title{Dependency Neural Networks}
6 | \usage{
7 | depna(neuralarray, cores, ...)
8 | }
9 | \arguments{
10 | \item{neuralarray}{Array from \code{\link{convertConnBrainMat}} function}
11 |
12 | \item{cores}{Numeric.
13 | Number of cores to use in computing results.
14 | Set to \code{1} to not use parallel computing.
15 | Recommended to use maximum number of cores minus one}
16 |
17 | \item{...}{Additional arguments from \code{\link{depend}} function}
18 | }
19 | \value{
20 | Returns an array of n x n x m dependency matrices
21 | }
22 | \description{
23 | Applies the dependency network approach to neural network array
24 | }
25 | \examples{
26 | \dontrun{
27 | neuralarray <- convertConnBrainMat()
28 |
29 | dependencyneuralarray <- depna(neuralarray)
30 | }
31 |
32 | }
33 | \references{
34 | Jacob, Y., Winetraub, Y., Raz, G., Ben-Simon, E., Okon-Singer, H., Rosenberg-Katz, K., ... & Ben-Jacob, E. (2016).
35 | Dependency Network Analysis (DEPNA) reveals context related influence of brain network nodes.
36 | \emph{Scientific Reports}, \emph{6}, 27444.
37 |
38 | Kenett, D. Y., Tumminello, M., Madi, A., Gur-Gershgoren, G., Mantegna, R. N., & Ben-Jacob, E. (2010).
39 | Dominating clasp of the financial sector revealed by partial correlation analysis of the stock market.
40 | \emph{PLoS one}, \emph{5}, e15032.
41 | }
42 | \author{
43 | Alexander Christensen
44 | }
45 |
--------------------------------------------------------------------------------
/man/desc.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/desc.R
3 | \name{desc}
4 | \alias{desc}
5 | \title{Variable Descriptive Statistics}
6 | \usage{
7 | desc(data, column, histplot = TRUE)
8 | }
9 | \arguments{
10 | \item{data}{A matrix or data frame}
11 |
12 | \item{column}{Column name or number in \code{data}}
13 |
14 | \item{histplot}{A histogram plot of the variable}
15 | }
16 | \value{
17 | A data frame containing values for \code{n} (number of cases),
18 | \code{missing} (number of missing cases), \code{mean}, \code{sd}, \code{min}, and \code{max}. \code{normal?}
19 | will contain yes/no for whether the variable is normally distributed based
20 | on the \code{\link{shapiro.test}} for a variable
21 | }
22 | \description{
23 | Computes \code{mean}, standard deviation (\code{sd}), minimum value (\code{min}),
24 | maximum value (\code{max}),
25 | and univariate normal statistics (\code{normal?}) for a variable
26 | }
27 | \examples{
28 |
29 | desc(neoOpen,1)
30 |
31 | }
32 | \author{
33 | Alexander Christensen
34 | }
35 |
--------------------------------------------------------------------------------
/man/desc.all.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/desc.all.R
3 | \name{desc.all}
4 | \alias{desc.all}
5 | \title{Dataset Descriptive Statistics}
6 | \usage{
7 | desc.all(data)
8 | }
9 | \arguments{
10 | \item{data}{A matrix or data frame}
11 | }
12 | \value{
13 | A data frame containing values for \code{n} (number of cases),
14 | \code{missing} (number of missing cases), \code{mean}, \code{sd}, \code{min}, and \code{max}. \code{normal?}
15 | will contain yes/no for whether the variable is normally distributed based
16 | on the \code{\link{shapiro.test}} for the entire dataset
17 | }
18 | \description{
19 | Computes \code{mean}, standard deviation (\code{sd}), minimum value (\code{min}),
20 | maximum value (\code{max}),
21 | and univariate normal statistics (\code{normal?}) for the entire dataset
22 | }
23 | \examples{
24 |
25 | desc.all(neoOpen)
26 |
27 | }
28 | \author{
29 | Alexander Christensen
30 | }
31 |
--------------------------------------------------------------------------------
/man/distance.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/distance.R
3 | \name{distance}
4 | \alias{distance}
5 | \title{Distance}
6 | \usage{
7 | distance(A, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{FALSE}.
14 | Set to \code{TRUE} for weighted measure of distance}
15 | }
16 | \value{
17 | A distance matrix of the network
18 | }
19 | \description{
20 | Computes distance matrix of the network
21 | }
22 | \examples{
23 | # Pearson's correlation only for CRAN checks
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | #Unweighted
27 | Du <- distance(A)
28 |
29 | #Weighted
30 | Dw <- distance(A, weighted = TRUE)
31 |
32 | }
33 | \references{
34 | Rubinov, M., & Sporns, O. (2010).
35 | Complex network measures of brain connectivity: Uses and interpretations.
36 | \emph{NeuroImage}, \emph{52}, 1059-1069.
37 | }
38 | \author{
39 | Alexander Christensen
40 | }
41 |
--------------------------------------------------------------------------------
/man/diversity.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/diversity.R
3 | \name{diversity}
4 | \alias{diversity}
5 | \title{Diversity Coefficient}
6 | \usage{
7 | diversity(A, comm = c("walktrap", "louvain"))
8 | }
9 | \arguments{
10 | \item{A}{Network adjacency matrix}
11 |
12 | \item{comm}{A vector of corresponding to each item's community.
13 | Defaults to \code{"walktrap"} for the \code{\link[igraph]{cluster_walktrap}} community detection algorithm.
14 | Set to \code{"louvain"} for the \code{\link[NetworkToolbox]{louvain}} community detection algorithm.
15 | Can also be set to user-specified communities (see examples)}
16 | }
17 | \value{
18 | Returns a list containing:
19 |
20 | \item{overall}{Diversity coefficient without signs considered}
21 |
22 | \item{positive}{Diversity coefficient with only positive sign}
23 |
24 | \item{negative}{Diversity coefficient with only negative sign}
25 | }
26 | \description{
27 | Computes the diversity coefficient for each node. The diversity
28 | coefficient measures a node's connections to communitites outside of its
29 | own community. Nodes that have many connections to other communities will
30 | have higher diversity coefficient values. Positive and negative signed weights
31 | for diversity coefficients are computed separately.
32 | }
33 | \details{
34 | Values closer to 1 suggest greater between-community connectivity and
35 | values closer to 0 suggest greater within-community connectivity
36 | }
37 | \examples{
38 | # Pearson's correlation only for CRAN checks
39 | A <- TMFG(neoOpen, normal = FALSE)$A
40 |
41 | #theoretical communities
42 | comm <- rep(1:8, each = 6)
43 |
44 | gdiv <- diversity(A, comm = comm)
45 |
46 | #walktrap communities
47 | wdiv <- diversity(A, comm = "walktrap")
48 |
49 | }
50 | \references{
51 | Rubinov, M., & Sporns, O. (2010).
52 | Complex network measures of brain connectivity: Uses and interpretations.
53 | \emph{NeuroImage}, \emph{52}, 1059-1069.
54 | }
55 | \author{
56 | Alexander Christensen
57 | }
58 |
--------------------------------------------------------------------------------
/man/edgerep.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/edgerep.R
3 | \name{edgerep}
4 | \alias{edgerep}
5 | \title{Edge Replication}
6 | \usage{
7 | edgerep(A, B, corr = c("pearson", "spearman", "kendall"))
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network A}
11 |
12 | \item{B}{An adjacency matrix of network B}
13 |
14 | \item{corr}{Correlation method for assessing the relationship between the replicated edge weights.
15 | Defaults to \code{"pearson"}.
16 | Set to \code{"spearman"} for non-linear or monotonic associations.
17 | Set to \code{"kendall"} for rank-order correlations}
18 | }
19 | \value{
20 | Returns a list containing:
21 |
22 | \item{replicatedEdges}{The edges that replicated and their weights}
23 |
24 | \item{replicated}{Number of edges that replicated}
25 |
26 | \item{meanDiff}{The average edge weight difference between the edges that replicated}
27 |
28 | \item{sdDiff}{The standard deviation edge weight difference between the edges that replicated}
29 |
30 | \item{cor}{The correlation between the edges that replicated}
31 |
32 | Lists for each network contain:
33 |
34 | \item{totalEdges}{Total possible number of edges to be replicated}
35 |
36 | \item{percentage}{Percentage of edges that replicated relative to total possible}
37 |
38 | \item{density}{The density of the network}
39 | }
40 | \description{
41 | Computes the number of edges that replicate between two cross-sectional networks
42 | }
43 | \examples{
44 | # normal set to FALSE for CRAN tests
45 | tmfg <- TMFG(neoOpen, normal = FALSE)$A
46 |
47 | # normal set to FALSE for CRAN tests
48 | mast <- MaST(neoOpen, normal = FALSE)
49 |
50 | edges <- edgerep(tmfg, mast)
51 |
52 | }
53 | \author{
54 | Alexander Christensen
55 | }
56 |
--------------------------------------------------------------------------------
/man/eigenvector.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/eigenvector.R
3 | \name{eigenvector}
4 | \alias{eigenvector}
5 | \title{Eigenvector Centrality}
6 | \usage{
7 | eigenvector(A, weighted = TRUE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{TRUE}.
14 | Set to \code{FALSE} for unweighted measure of eigenvector centrality}
15 | }
16 | \value{
17 | A vector of eigenvector centrality values for each node in the network
18 | }
19 | \description{
20 | Computes eigenvector centrality of each node in a network
21 | }
22 | \examples{
23 | # Pearson's correlation only for CRAN checks
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | #Weighted
27 | EC <- eigenvector(A)
28 |
29 | #Unweighted
30 | EC <- eigenvector(A, weighted = FALSE)
31 |
32 | }
33 | \references{
34 | Rubinov, M., & Sporns, O. (2010).
35 | Complex network measures of brain connectivity: Uses and interpretations.
36 | \emph{NeuroImage}, \emph{52}, 1059-1069.
37 | }
38 | \author{
39 | Alexander Christensen
40 | }
41 |
--------------------------------------------------------------------------------
/man/flow.frac.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/flow.frac.R
3 | \name{flow.frac}
4 | \alias{flow.frac}
5 | \title{Flow Fraction}
6 | \usage{
7 | flow.frac(A, nodes)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix}
11 |
12 | \item{nodes}{A subset of nodes in the network}
13 | }
14 | \value{
15 | Returns a flow fraction value
16 | }
17 | \description{
18 | Computes \code{\link[NetworkToolbox]{eigenvector}} centrality over nodes in a subset of nodes
19 | in the network. This measure generalizes across any subset of nodes and
20 | is not specific to communities
21 | }
22 | \examples{
23 | # Pearson's correlation only for CRAN checks
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | nodes <- seq(1,48,2)
27 |
28 | result <- flow.frac(A, nodes)
29 |
30 | }
31 | \references{
32 | Giscard, P. L., & Wilson, R. C. (2018).
33 | A centrality measure for cycles and subgraphs II.
34 | \emph{Applied Network Science}, \emph{3}, 9.
35 | }
36 | \author{
37 | Alexander Christensen
38 | }
39 |
--------------------------------------------------------------------------------
/man/gain.functions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/gain.functions.R
3 | \name{gain.functions}
4 | \alias{gain.functions}
5 | \alias{gfcnv_logdet}
6 | \alias{gfcnv_logdet_val}
7 | \alias{gdcnv_lmfit}
8 | \title{MFCF Gain Functions}
9 | \usage{
10 | "logLik"
11 | gfcnv_logdet(data, clique_id, cl, excl_nodes, ctreeControl)
12 |
13 | "logLik.val"
14 | gfcnv_logdet_val(data, clique_id, cl, excl_nodes, ctreeControl)
15 |
16 | "rSquared.val"
17 | gdcnv_lmfit(data, clique_id, cl, excl_nodes, ctreeControl)
18 | }
19 | \arguments{
20 | \item{data}{Matrix or data frame.
21 | Can be a dataset or a correlation matrix}
22 |
23 | \item{clique_id}{Numeric.
24 | Number corresponding to clique to add another node to}
25 |
26 | \item{cl}{List.
27 | List of cliques already assembled in the network}
28 |
29 | \item{excl_nodes}{Numeric vector.
30 | A vector of numbers corresponding to nodes not already
31 | included in the network}
32 |
33 | \item{ctreeControl}{List (length = 5).
34 | A list containing several parameters for controlling
35 | the clique tree sizes:
36 |
37 | \itemize{
38 |
39 | \item \code{min_size} --- Numeric. Minimum number of nodes allowed per
40 | clique. Defaults to \code{1}
41 |
42 | \item \code{max_size} --- Numeric. Maximum number of nodes allowed per
43 | clique. Defaults to \code{8}
44 |
45 | \item \code{pval} --- Numeric. \emph{p}-value used to determine cut-offs for nodes
46 | to include in a clique. Defaults to \code{.05}
47 |
48 | \item \code{pen} --- Numeric. Multiplies the number of edges added to penalize
49 | complex models. Similar to the penalty term in AIC
50 |
51 | \item \code{drop_sep} --- Boolean. This parameter influences the MFCF only. If TRUE any
52 | separator can be used only once, as in the TMFG.
53 |
54 | \item \code{use_returns} --- Boolean. Only used in rSquared.val. If set to TRUE the regression is
55 | performed on log-returns. Defaults to \code{FALSE}
56 |
57 | }}
58 | }
59 | \value{
60 | Returns the value with the maximum gain
61 | }
62 | \description{
63 | These functions maximize a gain criterion
64 | for adding a node to a clique (and the larger network).
65 | The flexibility of \code{\link[NetworkToolbox]{MFCF}}
66 | allows for any multivariate function to be used as a
67 | scoring function.
68 |
69 | \itemize{
70 |
71 | \item \code{"logLik"} --- The log determinant of the matrix restricted to
72 | the separator minus the log determinant of the matrix restricted
73 | to the clique.
74 |
75 | \item\code{"logLik.val"} --- \code{"logLik"} with a further validation based on
76 | the likelihood ratio. If the increase in gain is not significant
77 | the routine stops adding nodes to the separator.
78 |
79 | \item \code{"rSquared.val"} --- The R squared from the regression of the node against the clique. Only
80 | the clique nodes with a regression coefficient significantly different
81 | from zero are added to the separator / new clique. The gain is different from
82 | zero only if the F-values is significant, It assumed that the \code{data}
83 | matrix is a dataset of realizations (i.e., \code{p}
84 | variables and \code{n} observations).
85 |
86 | }
87 | }
88 | \references{
89 | Massara, G. P. & Aste, T. (2019).
90 | Learning clique forests.
91 | \emph{ArXiv}.
92 | }
93 | \author{
94 | Guido Previde Massara and Alexander Christensen
95 | }
96 |
--------------------------------------------------------------------------------
/man/gateway.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/gateway.R
3 | \name{gateway}
4 | \alias{gateway}
5 | \title{Gateway Coefficient}
6 | \usage{
7 | gateway(
8 | A,
9 | comm = c("walktrap", "louvain"),
10 | cent = c("strength", "betweenness")
11 | )
12 | }
13 | \arguments{
14 | \item{A}{Network adjacency matrix}
15 |
16 | \item{comm}{A vector of corresponding to each item's community.
17 | Defaults to \code{"walktrap"} for the \code{\link[igraph]{cluster_walktrap}} community detection algorithm.
18 | Set to \code{"louvain"} for the \code{\link[NetworkToolbox]{louvain}} community detection algorithm.
19 | Can also be set to user-specified communities (see examples)}
20 |
21 | \item{cent}{Centrality to community gateway coefficient.
22 | Defaults to \code{"strength"}.
23 | Set to \code{"betweenness"} to use the \code{\link[NetworkToolbox]{betweenness}} centrality}
24 | }
25 | \value{
26 | Returns a list containing:
27 |
28 | \item{overall}{Gateway coefficient without signs considered}
29 |
30 | \item{positive}{Gateway coefficient with only positive sign}
31 |
32 | \item{negative}{Gateway coefficient with only negative sign}
33 | }
34 | \description{
35 | Computes the gateway coefficient for each node. The gateway
36 | coefficient measures a node's connections between its community and other communities.
37 | Nodes that are solely responsible for inter-community connectivity will
38 | have higher gateway coefficient values. Positive and negative signed weights
39 | for gateway coefficients are computed separately.
40 | }
41 | \examples{
42 | #theoretical communities
43 | comm <- rep(1:8, each = 6)
44 |
45 | # Pearson's correlation only for CRAN checks
46 | A <- TMFG(neoOpen, normal = FALSE)$A
47 |
48 | gw <- gateway(A, comm = comm)
49 |
50 | #walktrap communities
51 | wgw <- gateway(A, comm = "walktrap")
52 |
53 | }
54 | \references{
55 | Rubinov, M., & Sporns, O. (2010).
56 | Complex network measures of brain connectivity: Uses and interpretations.
57 | \emph{NeuroImage}, \emph{52}, 1059-1069.
58 |
59 | Vargas, E. R., & Wahl, L. M. (2014).
60 | The gateway coefficient: A novel metric for identifying critical connections in modular networks.
61 | \emph{The European Physical Journal B}, \emph{87}, 1-10.
62 | }
63 | \author{
64 | Alexander Christensen
65 | }
66 |
--------------------------------------------------------------------------------
/man/hybrid.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/hybrid.R
3 | \name{hybrid}
4 | \alias{hybrid}
5 | \title{Hybrid Centrality}
6 | \usage{
7 | hybrid(A, BC = c("standard", "random"), beta)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{BC}{How should the betweenness centrality be computed?
13 | Defaults to \code{"random"}.
14 | Set to \code{"standard"} for standard \code{\link[NetworkToolbox]{betweenness}}.}
15 |
16 | \item{beta}{Beta parameter to be passed to the \code{\link[NetworkToolbox]{rspbc}} function
17 | Defaults to .01}
18 | }
19 | \value{
20 | A vector of hybrid centrality values for each node in the network
21 | (higher values are more central, lower values are more peripheral)
22 | }
23 | \description{
24 | Computes hybrid centrality of each node in a network
25 | }
26 | \examples{
27 | # Pearson's correlation only for CRAN checks
28 | A <- TMFG(neoOpen, normal = FALSE)$A
29 |
30 | HC <- hybrid(A)
31 | }
32 | \references{
33 | Christensen, A. P., Kenett, Y. N., Aste, T., Silvia, P. J., & Kwapil, T. R. (2018).
34 | Network structure of the Wisconsin Schizotypy Scales-Short Forms:
35 | Examining psychometric network filtering approaches.
36 | \emph{Behavior Research Methods}, \emph{50}, 2531-2550.
37 |
38 | Pozzi, F., Di Matteo, T., & Aste, T. (2013).
39 | Spread of risk across financial markets: Better to invest in the peripheries.
40 | \emph{Scientific Reports}, \emph{3}, 1655.
41 | }
42 | \author{
43 | Alexander Christensen
44 | }
45 |
--------------------------------------------------------------------------------
/man/impact.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/impact.R
3 | \name{impact}
4 | \alias{impact}
5 | \title{Node Impact}
6 | \usage{
7 | impact(A)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 | }
12 | \value{
13 | A vector of node impact values for each node in the network
14 | (impact > 0, greater ASPL when node is removed; impact < 0,
15 | lower ASPL when node is removed)
16 | }
17 | \description{
18 | Computes impact measure or how much the average distance in the
19 | network changes with that node removed of each node in a network
20 | (\strong{Please see and cite Kenett et al., 2011})
21 | }
22 | \examples{
23 | # normal set to FALSE for CRAN tests
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | nodeimpact <- impact(A)
27 |
28 | }
29 | \references{
30 | Cotter, K. N., Christensen, A. P., & Silvia, P. J. (in press).
31 | Understanding inner music: A dimensional approach to musical imagery.
32 | \emph{Psychology of Aesthetics, Creativity, and the Arts}.
33 |
34 | Kenett, Y. N., Kenett, D. Y., Ben-Jacob, E., & Faust, M. (2011).
35 | Global and local features of semantic networks: Evidence from the Hebrew mental lexicon.
36 | \emph{PLoS one}, \emph{6}, e23912.
37 | }
38 | \author{
39 | Alexander Christensen
40 | }
41 |
--------------------------------------------------------------------------------
/man/is.graphical.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is.graphical.R
3 | \name{is.graphical}
4 | \alias{is.graphical}
5 | \title{Determines if Network is Graphical}
6 | \usage{
7 | is.graphical(A)
8 | }
9 | \arguments{
10 | \item{A}{A partial correlation network (adjacency matrix)}
11 | }
12 | \value{
13 | Returns a TRUE/FALSE for whether network is graphical
14 | }
15 | \description{
16 | Tests for whether the network is graphical.
17 | Input must be a partial correlation network.
18 | Function assumes that partial correlations were computed from a multivariate normal distribution
19 | }
20 | \examples{
21 | \dontrun{
22 | A <- LoGo(neoOpen, normal = TRUE, partial = TRUE)
23 |
24 | is.graphical(A)
25 | }
26 |
27 | }
28 | \author{
29 | Alexander Christensen
30 | }
31 |
--------------------------------------------------------------------------------
/man/kld.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/kld.R
3 | \name{kld}
4 | \alias{kld}
5 | \title{Kullback-Leibler Divergence}
6 | \usage{
7 | kld(base, test)
8 | }
9 | \arguments{
10 | \item{base}{Full or base model}
11 |
12 | \item{test}{Reduced or testing model}
13 | }
14 | \value{
15 | A value greater than 0.
16 | Smaller values suggest the probability distribution of the reduced model is near the full model
17 | }
18 | \description{
19 | Estimates the Kullback-Leibler Divergence which measures how one probability distribution
20 | diverges from the original distribution (equivalent means are assumed)
21 | Matrices \strong{must} be positive definite inverse covariance matrix for accurate measurement.
22 | This is a \strong{relative} metric
23 | }
24 | \examples{
25 | A1 <- solve(cov(neoOpen))
26 |
27 | \dontrun{
28 | A2 <- LoGo(neoOpen)
29 |
30 | kld_value <- kld(A1, A2)
31 | }
32 |
33 | }
34 | \references{
35 | Kullback, S., & Leibler, R. A. (1951).
36 | On information and sufficiency.
37 | \emph{The Annals of Mathematical Statistics}, \emph{22}, 79-86.
38 | }
39 | \author{
40 | Alexander Christensen
41 | }
42 |
--------------------------------------------------------------------------------
/man/lattnet.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lattnet.R
3 | \name{lattnet}
4 | \alias{lattnet}
5 | \title{Generates a Lattice Network}
6 | \usage{
7 | lattnet(nodes, edges)
8 | }
9 | \arguments{
10 | \item{nodes}{Number of nodes in lattice network}
11 |
12 | \item{edges}{Number of edges in lattice network}
13 | }
14 | \value{
15 | Returns an adjacency matrix of a lattice network
16 | }
17 | \description{
18 | Generates a lattice network
19 | }
20 | \examples{
21 | latt <- lattnet(10, 27)
22 |
23 | }
24 | \references{
25 | Rubinov, M., & Sporns, O. (2010).
26 | Complex network measures of brain connectivity: Uses and interpretations.
27 | \emph{NeuroImage}, \emph{52}, 1059-1069.
28 | }
29 | \author{
30 | Alexander Christensen
31 | }
32 |
--------------------------------------------------------------------------------
/man/leverage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/leverage.R
3 | \name{leverage}
4 | \alias{leverage}
5 | \title{Leverage Centrality}
6 | \usage{
7 | leverage(A, weighted = TRUE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{TRUE}.
14 | Set to \code{FALSE} for unweighted measure of leverage centrality}
15 | }
16 | \value{
17 | A vector of leverage centrality values for each node in the network
18 | }
19 | \description{
20 | Computes leverage centrality of each node in a network
21 | (the degree of connected neighbors; \strong{Please see and cite Joyce et al., 2010})
22 | }
23 | \examples{
24 | # Pearson's correlation only for CRAN checks
25 | A <- TMFG(neoOpen, normal = FALSE)$A
26 |
27 | #Weighted
28 | levW <- leverage(A)
29 |
30 | #Unweighted
31 | levU <- leverage(A, weighted = FALSE)
32 |
33 | }
34 | \references{
35 | Joyce, K. E., Laurienti, P. J., Burdette, J. H., & Hayasaka, S. (2010).
36 | A new measure of centrality for brain networks.
37 | \emph{PLoS One}, \emph{5} e12200.
38 | }
39 | \author{
40 | Alexander Christensen
41 | }
42 |
--------------------------------------------------------------------------------
/man/louvain.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/louvain.R
3 | \name{louvain}
4 | \alias{louvain}
5 | \title{Louvain Community Detection Algorithm}
6 | \usage{
7 | louvain(A, gamma, M0)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{gamma}{Defaults to \code{1}.
13 | Set to \code{gamma} > 1 to detect smaller modules and \code{gamma} < 1 for larger modules}
14 |
15 | \item{M0}{Input can be an initial community vector.
16 | Defaults to \code{NULL}}
17 | }
18 | \value{
19 | Returns a list containing:
20 |
21 | \item{community}{A community vector corresponding to each node's community}
22 |
23 | \item{Q}{Modularity statistic. A measure of how well the communities are compartmentalized}
24 | }
25 | \description{
26 | Computes a vector of communities (community) and a global modularity measure (Q)
27 | }
28 | \examples{
29 | # Pearson's correlation only for CRAN checks
30 | A <- TMFG(neoOpen, normal = FALSE)$A
31 |
32 | modularity <- louvain(A)
33 |
34 | }
35 | \references{
36 | Blondel, V. D., Guillaume, J. L., Lambiotte, R., & Lefebvre, E. (2008).
37 | Fast unfolding of communities in large networks.
38 | \emph{Journal of Statistical Mechanics: Theory and Experiment}, \emph{2008}, P10008.
39 |
40 | Rubinov, M., & Sporns, O. (2010).
41 | Complex network measures of brain connectivity: Uses and interpretations.
42 | \emph{NeuroImage}, \emph{52}, 1059-1069.
43 | }
44 | \author{
45 | Alexander Christensen
46 | }
47 |
--------------------------------------------------------------------------------
/man/neoOpen.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/neoOpen.R
3 | \docType{data}
4 | \name{neoOpen}
5 | \alias{neoOpen}
6 | \title{NEO-PI-3 Openness to Experience Data}
7 | \format{
8 | A 802x48 response matrix
9 | }
10 | \usage{
11 | data(neoOpen)
12 | }
13 | \description{
14 | A response matrix (\emph{n} = 802) of NEO-PI-3's Openness to Experience
15 | from Christensen, Cotter, & Silvia (2019).
16 | }
17 | \examples{
18 | data("neoOpen")
19 |
20 | }
21 | \references{
22 | Christensen, A. P., Cotter, K. N., & Silvia, P. J. (2019).
23 | Reopening openness to experience: A network analysis of four openness to experience inventories.
24 | \emph{Journal of Personality Assessment}, \emph{101}, 574-588.
25 | }
26 | \keyword{datasets}
27 |
--------------------------------------------------------------------------------
/man/net.coverage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/net.coverage.R
3 | \name{net.coverage}
4 | \alias{net.coverage}
5 | \title{Network Coverage}
6 | \usage{
7 | net.coverage(A, nodes, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix}
11 |
12 | \item{nodes}{Subset of nodes to examine the coverage of the network}
13 |
14 | \item{weighted}{Is the network weighted?
15 | Defaults to \code{FALSE}.
16 | Set to \code{TRUE} for weighted measures}
17 | }
18 | \value{
19 | Returns a list containing:
20 |
21 | \item{mean}{The average distance from the subset of nodes to all other nodes in the network}
22 |
23 | \item{sd}{The standard deviation of distance from the subset of nodes to all other nodes in the network}
24 |
25 | \item{range}{The range of distance from the subset of nodes to all other nodes in the network}
26 | }
27 | \description{
28 | Computes the mean distance across a subset of nodes in a network.
29 | This measure can be used to identify the effectiveness of a subset of nodes'
30 | coverage of the network space
31 | }
32 | \examples{
33 | # Pearson's correlation only for CRAN checks
34 | A <- TMFG(neoOpen, normal = FALSE)$A
35 |
36 | nodes <- seq(1,48,2)
37 |
38 | result <- net.coverage(A, nodes)
39 |
40 | }
41 | \references{
42 | Christensen, A. P., Cotter, K. N., Silvia, P. J., & Benedek, M. (2018)
43 | Scale development via network analysis: A comprehensive and concise measure of Openness to Experience
44 | \emph{PsyArXiv}, 1-40.
45 | }
46 | \author{
47 | Alexander Christensen and
48 | Mathias Benedek
49 | }
50 |
--------------------------------------------------------------------------------
/man/network.coverage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/network.coverage.R
3 | \name{network.coverage}
4 | \alias{network.coverage}
5 | \title{Network Coverage}
6 | \usage{
7 | network.coverage(A, nodes, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix}
11 |
12 | \item{nodes}{Subset of nodes to examine the coverage of the network}
13 |
14 | \item{weighted}{Is the network weighted?
15 | Defaults to \code{FALSE}.
16 | Set to \code{TRUE} for weighted measures}
17 | }
18 | \value{
19 | Returns a list containing:
20 |
21 | \item{mean}{The average distance from the subset of nodes to all other nodes in the network}
22 |
23 | \item{sd}{The standard deviation of distance from the subset of nodes to all other nodes in the network}
24 |
25 | \item{range}{The range of distance from the subset of nodes to all other nodes in the network}
26 | }
27 | \description{
28 | Computes the mean distance across a subset of nodes in a network.
29 | This measure can be used to identify the effectiveness of a subset of nodes'
30 | coverage of the network space
31 | }
32 | \examples{
33 | # Pearson's correlation only for CRAN checks
34 | A <- TMFG(neoOpen, normal = FALSE)$A
35 |
36 | nodes <- seq(1,48,2)
37 |
38 | result <- network.coverage(A, nodes)
39 |
40 | }
41 | \references{
42 | Christensen, A. P., Cotter, K. N., Silvia, P. J., & Benedek, M. (2018)
43 | Scale development via network analysis: A comprehensive and concise measure of Openness to Experience
44 | \emph{PsyArXiv}, 1-40.
45 | }
46 | \author{
47 | Alexander Christensen and Mathias Benedek
48 | }
49 |
--------------------------------------------------------------------------------
/man/network.permutation.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/network.permutation.R
3 | \name{network.permutation}
4 | \alias{network.permutation}
5 | \title{Permutation Test for Network Measures}
6 | \usage{
7 | network.permutation(
8 | sample1 = NULL,
9 | sample2 = NULL,
10 | iter,
11 | network = c("glasso", "ising", "TMFG", "LoGo"),
12 | measure = c("betweenness", "closeness", "strength", "eigenvector", "rspbc", "hybrid",
13 | "ASPL", "CC", "S", "Q"),
14 | alternative = c("less", "greater", "two.tailed"),
15 | ncores,
16 | prev.perm = NULL,
17 | ...
18 | )
19 | }
20 | \arguments{
21 | \item{sample1}{Matrix or data frame.
22 | Sample to be compared with \code{sample2}}
23 |
24 | \item{sample2}{Matrix or data frame.
25 | Sample to be compared with \code{sample1}}
26 |
27 | \item{iter}{Numeric.
28 | Number of iterations to perform.
29 | Defaults to \code{1000}}
30 |
31 | \item{network}{Character.
32 | Network estimation method to apply to the datasets.
33 | Defaults to \code{"glasso"}}
34 |
35 | \item{measure}{Character.
36 | Network measure to be compared in the permutation test}
37 |
38 | \item{alternative}{Character.
39 | Alternative hypothesis test to perform.
40 | Defaults to \code{"two.tailed"}}
41 |
42 | \item{ncores}{Numeric.
43 | Number of computer processing cores to use for bootstrapping samples.
44 | Defaults to \emph{n} - 1 total number of cores.
45 | Set to any number between 1 and maximum amount of cores on your computer
46 | (see \code{parellel::detectCores()})}
47 |
48 | \item{prev.perm}{\code{network.permutation} class object.
49 | An object of previously performed permutation test. The
50 | networks generated in the previous permutation will be
51 | used to compute other network measures. This saves time
52 | when computing multiple permutation tests}
53 |
54 | \item{...}{Additional arguments for \code{\link[qgraph]{EBICglasso}}}
55 | }
56 | \value{
57 | Returns a list containing two objects:
58 |
59 | \item{result}{The results of the permutation test. For centrality measures,
60 | this is a matrix where the rows represent each node and the columns are
61 | the observed values of the centrality measure for \code{sample1}, \code{sample2},
62 | and the \emph{p}-value from the permutation test. For global network measures,
63 | this is a vector with the observed values of the global network measure for
64 | \code{sample1}, \code{sample2}, and the \emph{p}-value from the permutation test.}
65 |
66 | \item{networks}{A list containing two lists: \code{network1} and \code{network2}.
67 | The network lists correspond to the networks generated in the permutation test
68 | for \code{sample1} and \code{sample2}, respectively. This output is used primarily
69 | for the computation of other network measures using the same datasets
70 | (see \code{prev.perm} explanation)}
71 | }
72 | \description{
73 | Computes a permutation test to determine whether
74 | there are difference in centrality and global network measures
75 | }
76 | \examples{
77 | # Split data (only for example)
78 | split1 <- neoOpen[c(1:401),]
79 | split2 <- neoOpen[c(402:802),]
80 |
81 | \donttest{
82 | # Perform permutation test
83 | perm.str <- network.permutation(split1, split2, iter = 1000, network = "glasso",
84 | measure = "strength", alternative = "two.tailed", ncores = 2)
85 |
86 | # Check results
87 | perm.str$result
88 |
89 | # Permutation to check other measures (using networks from previous result)
90 | perm.aspl <- network.permutation(prev.perm = perm.str, measure = "ASPL", ncores = 2)
91 |
92 | # Check results
93 | perm.aspl$result}
94 |
95 | }
96 | \author{
97 | Alexander Christensen
98 | }
99 |
--------------------------------------------------------------------------------
/man/neuralnetfilter.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/neuralnetfilter.R
3 | \name{neuralnetfilter}
4 | \alias{neuralnetfilter}
5 | \title{Neural Network Filter}
6 | \usage{
7 | neuralnetfilter(
8 | neuralarray,
9 | method = c("TMFG", "MaST", "ECOplusMaST", "ECO", "threshold"),
10 | progBar = TRUE,
11 | ...
12 | )
13 | }
14 | \arguments{
15 | \item{neuralarray}{Array from \code{\link{convertConnBrainMat}} function}
16 |
17 | \item{method}{Filtering method to be applied}
18 |
19 | \item{progBar}{Should progress bar be displayed?
20 | Defaults to \code{TRUE}.
21 | Set \code{FALSE} for no progress bar}
22 |
23 | \item{...}{Additional arguments from network filtering methods}
24 | }
25 | \value{
26 | Returns an array of n x n x m filtered matrices
27 | }
28 | \description{
29 | Applies a network filtering methodology to neural network array.
30 | Removes edges from the neural network output from \code{\link{convertConnBrainMat}}
31 | using a network filtering approach
32 | }
33 | \examples{
34 | \dontrun{neuralarray <- convertConnBrainMat()
35 |
36 | filteredneuralarray <- neuralnetfilter(neuralarray, method = "threshold", thresh = .50)
37 |
38 | dependencyarray <- depna(neuralarray)
39 |
40 | filtereddependencyarray <- neuralnetfilter(dependencyarray, method = "TMFG", depend = TRUE)
41 | }
42 |
43 | }
44 | \author{
45 | Alexander Christensen
46 | }
47 |
--------------------------------------------------------------------------------
/man/openness.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/openness.R
3 | \docType{data}
4 | \name{openness}
5 | \alias{openness}
6 | \alias{openness.key}
7 | \title{Four Inventories of Openness to Experience}
8 | \format{
9 | A 794 x 138 response matrix (openness) and 138 x 7 matrix (openness.key).
10 | Here are detailed descriptions of the key:
11 |
12 | \itemize{
13 |
14 | \item \code{Inventory} --- The personality inventory the item belongs to
15 |
16 | \item \code{Facet} --- The personality inventory defined facet
17 |
18 | \item \code{JPA.Domains} --- The broad domains identified by Christensen, Cotter, and Silvia (2019)
19 |
20 | \item \code{JPA.Facets} --- The facets identified by Christensen, Cotter, and Silvia (2019)
21 |
22 | \item \code{Item.Label} --- The labels used in Christensen, Cotter, and Silvia (2019)
23 |
24 | \item \code{Item.Description} --- Descriptions of each item. Note that the NEO-PI-3 items are protected by
25 | copyright and therefore have been paraphrased. These item descriptions
26 | do not represent the item as given to the participant
27 |
28 | \item \code{Reversed} --- Whether an item should be reversed or not (\code{openness} is already reversed)
29 |
30 | }
31 | }
32 | \usage{
33 | data(openness)
34 |
35 | data(openness.key)
36 | }
37 | \description{
38 | A response matrix (\emph{n} = 794) of all four Openness to Experience
39 | inventories from Christensen, Cotter, & Silvia (2019). The
40 | key provides inventory, facet, and item description information
41 | for the item labels. Note that because of NEO's copyrights the
42 | items have been shortened and paraphrased
43 | }
44 | \examples{
45 | # Loading data
46 | data("openness")
47 | data("openness.key")
48 |
49 | # Change item labels
50 | colnames(openness) <- openness.key$Item.Description
51 |
52 | }
53 | \references{
54 | Christensen, A. P., Cotter, K. N., & Silvia, P. J. (2019).
55 | Reopening openness to experience: A network analysis of four openness to experience inventories.
56 | \emph{Journal of Personality Assessment}, \emph{101}, 574-588.
57 | }
58 | \keyword{datasets}
59 |
--------------------------------------------------------------------------------
/man/participation.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/participation.R
3 | \name{participation}
4 | \alias{participation}
5 | \title{Participation Coefficient}
6 | \usage{
7 | participation(A, comm = c("walktrap", "louvain"))
8 | }
9 | \arguments{
10 | \item{A}{Network adjacency matrix}
11 |
12 | \item{comm}{A vector of corresponding to each item's community.
13 | Defaults to \code{"walktrap"} for the \code{\link[igraph]{cluster_walktrap}} community detection algorithm.
14 | Set to \code{"louvain"} for the \code{\link[NetworkToolbox]{louvain}} community detection algorithm.
15 | Can also be set to user-specified communities (see examples)}
16 | }
17 | \value{
18 | Returns a list containing:
19 |
20 | \item{overall}{Participation coefficient without signs considered}
21 |
22 | \item{positive}{Participation coefficient with only positive sign}
23 |
24 | \item{negative}{Participation coefficient with only negative sign}
25 | }
26 | \description{
27 | Computes the participation coefficient for each node. The participation
28 | coefficient measures the strength of a node's connections within its community. Positive
29 | and negative signed weights for participation coefficients are computed separately.
30 | }
31 | \details{
32 | Values closer to 0 suggest greater within-community connectivity and
33 | values closer to 1 suggest greater between-community connectivity
34 | }
35 | \examples{
36 | #theoretical factors
37 | comm <- rep(1:8, each = 6)
38 |
39 | # Pearson's correlation only for CRAN checks
40 | A <- TMFG(neoOpen, normal = FALSE)$A
41 |
42 | pc <- participation(A, comm = comm)
43 |
44 | # Walktrap factors
45 | wpc <- participation(A, comm = "walktrap")
46 |
47 | }
48 | \references{
49 | Guimera, R., & Amaral, L. A. N. (2005).
50 | Functional cartography of complex metabolic networks.
51 | \emph{Nature}, \emph{433}, 895-900.
52 |
53 | Rubinov, M., & Sporns, O. (2010).
54 | Complex network measures of brain connectivity: Uses and interpretations.
55 | \emph{NeuroImage}, \emph{52}, 1059-1069.
56 | }
57 | \author{
58 | Alexander Christensen
59 | }
60 |
--------------------------------------------------------------------------------
/man/pathlengths.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/pathlengths.R
3 | \name{pathlengths}
4 | \alias{pathlengths}
5 | \title{Characteristic Path Lengths}
6 | \usage{
7 | pathlengths(A, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{FALSE}.
14 | Set to \code{TRUE} for weighted measures}
15 | }
16 | \value{
17 | Returns a list containing:
18 |
19 | \item{ASPL}{Global average shortest path length}
20 |
21 | \item{ASPLi}{Local average shortest path length}
22 |
23 | \item{ecc}{Eccentricity (i.e., maximal shortest path length between a node and any other node)}
24 |
25 | \item{D}{Diameter of the network (i.e., the maximum of eccentricity)}
26 | }
27 | \description{
28 | Computes global average shortest path length,
29 | local average shortest path length, eccentricity,
30 | and diameter of a network
31 | }
32 | \examples{
33 | # Pearson's correlation only for CRAN checks
34 | A <- TMFG(neoOpen, normal = FALSE)$A
35 |
36 | #Unweighted
37 | PL <- pathlengths(A)
38 |
39 | #Weighted
40 | PL <- pathlengths(A, weighted = TRUE)
41 |
42 | }
43 | \references{
44 | Rubinov, M., & Sporns, O. (2010).
45 | Complex network measures of brain connectivity: Uses and interpretations.
46 | \emph{NeuroImage}, \emph{52}, 1059-1069.
47 | }
48 | \author{
49 | Alexander Christensen
50 | }
51 |
--------------------------------------------------------------------------------
/man/plot.cpm.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot.cpm.R
3 | \name{plot.cpm}
4 | \alias{plot.cpm}
5 | \title{Plots CPM results}
6 | \usage{
7 | \method{plot}{cpm}(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{A \code{\link[NetworkToolbox]{cpm}} object}
11 |
12 | \item{...}{Additional arguments for \link{plot}}
13 | }
14 | \description{
15 | Plots CPM results
16 | }
17 | \author{
18 | Alexander Christensen
19 | }
20 |
--------------------------------------------------------------------------------
/man/randnet.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/randnet.R
3 | \name{randnet}
4 | \alias{randnet}
5 | \title{Generates a Random Network}
6 | \usage{
7 | randnet(nodes = NULL, edges = NULL, A = NULL)
8 | }
9 | \arguments{
10 | \item{nodes}{Numeric.
11 | Number of nodes in random network}
12 |
13 | \item{edges}{Numeric.
14 | Number of edges in random network}
15 |
16 | \item{A}{Matrix or data frame.
17 | An adjacency matrix (i.e., network) to be used to estimated a random network with
18 | fixed edges (allows for asymmetric network estimation)}
19 | }
20 | \value{
21 | Returns an adjacency matrix of a random network
22 | }
23 | \description{
24 | Generates a random binary network
25 | }
26 | \examples{
27 | rand <- randnet(10, 27)
28 |
29 | }
30 | \references{
31 | Rubinov, M., & Sporns, O. (2010).
32 | Complex network measures of brain connectivity: Uses and interpretations.
33 | \emph{NeuroImage}, \emph{52}, 1059-1069.
34 |
35 | Csardi, G., & Nepusz, T. (2006).
36 | The \emph{igraph} software package for complex network research.
37 | \emph{InterJournal, Complex Systems}, 1695.
38 | }
39 | \author{
40 | Alexander Christensen
41 | }
42 |
--------------------------------------------------------------------------------
/man/reg.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/reg.R
3 | \name{reg}
4 | \alias{reg}
5 | \title{Regression Matrix}
6 | \usage{
7 | reg(
8 | data,
9 | family = c("binomial", "gaussian", "Gamma", "poisson"),
10 | symmetric = TRUE
11 | )
12 | }
13 | \arguments{
14 | \item{data}{A dataset}
15 |
16 | \item{family}{Error distribution to be used in the regression model.
17 | Defaults to \code{"logistic"}.
18 | Set to any family used in function \code{\link[stats]{family}}}
19 |
20 | \item{symmetric}{Should matrix be symmetric?
21 | Defaults to \code{TRUE}, taking the mean of the two edge weights
22 | (i.e., \code{[i,j]} and \code{[j,i]})
23 | Set to \code{FALSE} for asymmetric weights
24 | (i.e., \code{[i,j]} does not equal \code{[j,i]})}
25 | }
26 | \value{
27 | A matrix of fully regressed coefficients where
28 | one variable is regressed over all others
29 | }
30 | \description{
31 | Computes regression such that one variable is regressed over all other variables
32 | }
33 | \examples{
34 | #binarize responses
35 | psyb <- ifelse(neoOpen>=4, 1, 0)
36 |
37 | \dontrun{
38 | #perform logistic regression
39 | mat <- reg(psyb)}
40 |
41 | }
42 | \author{
43 | Alexander Christensen
44 | }
45 |
--------------------------------------------------------------------------------
/man/resp.rep.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/resp.rep.R
3 | \name{resp.rep}
4 | \alias{resp.rep}
5 | \title{Repeated Responses Check}
6 | \usage{
7 | resp.rep(data, scale.lens = NULL, max.val, reverse = NULL, freq.prop = 0.8)
8 | }
9 | \arguments{
10 | \item{data}{A dataset}
11 |
12 | \item{scale.lens}{The number of items for each scale in the data.
13 | A vector indicating the length for each scale to be checked in the data}
14 |
15 | \item{max.val}{Maximum value for data (or scales).
16 | If scales have different maximum values, then a vector must be
17 | input with each scale's maximum value (see examples)}
18 |
19 | \item{reverse}{Reverse scored responses.
20 | If responses have not yet reversed, then do not reverse them.
21 | If responses have been reversed, then a vector indicating
22 | which responses have been reverse-scored should be input (see examples).
23 | Can be TRUE/FALSE or 1/0 (reversed/not reversed)}
24 |
25 | \item{freq.prop}{Frequency proportion of the response values.
26 | Allows the researcher to determine the maximum frequency proportion
27 | of a certain response value is suspicious.
28 | The default is set to \code{.80} (or 80 percent responses are a single value)}
29 | }
30 | \value{
31 | Returns a matrix when \code{scale.lens = NULL} and a
32 | list with elements corresponding to the order of scales. In general,
33 | the output contains potential bad cases that should be further
34 | inspected by the researcher.
35 | }
36 | \description{
37 | Screens data to identify potential cases of repeated responding.
38 | The function is based on two criteria: no variance (i.e., a standard
39 | deviation of zero for given responses)and frequency proportion of the
40 | response values (which is set by \code{freq.prop}). Note that these
41 | criteria are highly related. Additional criteria will be added in
42 | the future.
43 | }
44 | \details{
45 | If a case is returned, then it does not mean that it is a bad case.
46 | Researchers should thoroughly inspect each case that is returned.
47 | A general guideline is that if a participant responded with all middle
48 | values (e.g., all 3's on a 5-point Likert scale), then they should be
49 | dropped. Note that a participant who responds with all maximum or
50 | minimum values may be a real case or a bad case. It is up to the
51 | researcher to decide and justify why or why not a case is kept.
52 | }
53 | \examples{
54 | #Re-reverse responses
55 | rev.vec <- c(TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,
56 | TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,
57 | FALSE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,
58 | FALSE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE)
59 |
60 | #Maximum value (5-point Likert scale)
61 | mv.vec <- 5
62 |
63 | #Repeated responses check
64 | resp.rep(neoOpen, reverse = rev.vec, max.val = mv.vec)
65 |
66 | #Example with multiple scales
67 |
68 | #Facet scale lengths of NEO-PI-3 Openness to Experience
69 | s.len <- c(8, 8, 8, 8, 8, 8)
70 |
71 | #Maximum values
72 | mv.vec <- c(5, 5, 5, 5, 5, 5)
73 |
74 | #Re-reverse responses
75 | rev.vec <- c(TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,
76 | TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,
77 | FALSE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,
78 | FALSE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,TRUE,FALSE,TRUE)
79 |
80 | #Repeated responses check
81 | resp.rep(neoOpen, scale.lens = s.len, max.val = mv.vec, reverse = rev.vec)
82 |
83 | }
84 | \author{
85 | Alexander Christensen
86 | }
87 |
--------------------------------------------------------------------------------
/man/rmse.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/rmse.R
3 | \name{rmse}
4 | \alias{rmse}
5 | \title{Root Mean Square Error}
6 | \usage{
7 | rmse(base, test)
8 | }
9 | \arguments{
10 | \item{base}{Base (or full) model to be evaluated against}
11 |
12 | \item{test}{Reduced (or testing) model (e.g., a sparse correlation or covariance matrix)}
13 | }
14 | \value{
15 | RMSE value (lower values suggest more similarity between the full and sparse model)
16 | }
17 | \description{
18 | Computes the root mean square error (RMSE) of a sparse model to a full model
19 | }
20 | \examples{
21 | A1 <- solve(cov(neoOpen))
22 |
23 | \dontrun{
24 | A2 <- LoGo(neoOpen)
25 |
26 | root <- rmse(A1, A2)
27 | }
28 |
29 | }
30 | \author{
31 | Alexander Christensen
32 | }
33 |
--------------------------------------------------------------------------------
/man/rspbc.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/rspbc.R
3 | \name{rspbc}
4 | \alias{rspbc}
5 | \title{Randomized Shortest Paths Betweenness Centrality}
6 | \usage{
7 | rspbc(A, beta = 0.01, comm = NULL)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{beta}{Sets the beta parameter.
13 | Defaults to \code{0.01} (recommended).
14 | Beta > 0.01 measure gets closer to weighted
15 | betweenness centrality (10) and beta < 0.01
16 | measure gets closer to degree (.0001)}
17 |
18 | \item{comm}{Vector.
19 | Community vector containing a value for each node.
20 | Computes "bridge" RSPBC, where the number of times
21 | a node is used on a random path between to another community}
22 | }
23 | \value{
24 | A vector of randomized shortest paths betweenness
25 | centrality values for each node in the network
26 | }
27 | \description{
28 | Computes betweenness centrality based on randomized shortest paths
29 | of each node in a network
30 | (\strong{Please see and cite Kivimaki et al., 2016})
31 | }
32 | \examples{
33 | # Pearson's correlation only for CRAN checks
34 | A <- TMFG(neoOpen, normal = FALSE)$A
35 |
36 | rspbc <- rspbc(A, beta=0.01)
37 |
38 | }
39 | \references{
40 | Kivimaki, I., Lebichot, B., Saramaki, J., & Saerens, M. (2016).
41 | Two betweenness centrality measures based on Randomized Shortest Paths.
42 | \emph{Scientific Reports}, \emph{6}, 19668.
43 | }
44 | \author{
45 | Alexander Christensen
46 | }
47 |
--------------------------------------------------------------------------------
/man/sim.chordal.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/sim.chordal.R
3 | \name{sim.chordal}
4 | \alias{sim.chordal}
5 | \title{Simulate Chordal Network}
6 | \usage{
7 | sim.chordal(
8 | nodes,
9 | inverse = c("cases", "matrix"),
10 | n = NULL,
11 | ordinal = FALSE,
12 | ordLevels = NULL,
13 | idio = NULL,
14 | eps = NULL
15 | )
16 | }
17 | \arguments{
18 | \item{nodes}{Numeric.
19 | Number of nodes in the simulated network}
20 |
21 | \item{inverse}{Character.
22 | Method to produce inverse covariance matrix.
23 |
24 | \itemize{
25 |
26 | \item \code{"cases"} --- Estimates inverse covariance matrix
27 | based on \code{n} number of cases and \code{nodes} number of
28 | variables, which are drawn from a random normal distribution
29 | \code{rnorm}. Data generated will be continuous unless
30 | \code{ordinal} is set to \code{TRUE}
31 |
32 | \item \code{"matrix"} --- Estimates inverse covariance matrix
33 | based on sigma
34 |
35 | }}
36 |
37 | \item{n}{Numeric.
38 | Number of cases in the simulated dataset}
39 |
40 | \item{ordinal}{Boolean.
41 | Should simulated continuous data be converted to ordinal?
42 | Defaults to \code{FALSE}.
43 | Set to \code{TRUE} for simulated ordinal data}
44 |
45 | \item{ordLevels}{Numeric.
46 | If \code{ordinal = TRUE}, then how many levels should be used?
47 | Defaults to \code{5}.
48 | Set to desired number of intervals}
49 |
50 | \item{idio}{Numeric.
51 | DESCRIPTION.
52 | Defaults to \code{0.10}}
53 |
54 | \item{eps}{Numeric.
55 | DESCRIPTION.
56 | Defaults to \code{2}}
57 | }
58 | \value{
59 | Returns a list containing:
60 |
61 | \item{cliques}{The cliques in the network}
62 |
63 | \item{separators}{The separators in the network}
64 |
65 | \item{inverse}{Simulated inverse covariance matrix of the network}
66 |
67 | \item{data}{Simulated data from sim.correlation in the \code{psych}
68 | package based on the simulated network}
69 | }
70 | \description{
71 | Simulates a chordal network based on number of nodes.
72 | Data will also be simulated based on the true network structure
73 | }
74 | \examples{
75 | #Continuous data
76 | sim.Norm <- sim.chordal(nodes = 20, inverse = "cases", n = 1000)
77 |
78 | #Ordinal data
79 | sim.Likert <- sim.chordal(nodes = 20, inverse = "cases", n = 1000, ordinal = TRUE)
80 |
81 | #Dichotomous data
82 | sim.Binary <- sim.chordal(nodes = 20, inverse = "cases", n = 1000, ordinal = TRUE, ordLevels = 5)
83 |
84 | }
85 | \references{
86 | Massara, G. P. & Aste, T. (2019).
87 | Learning clique forests.
88 | \emph{ArXiv}.
89 | }
90 | \author{
91 | Guido Previde Massara
92 | }
93 |
--------------------------------------------------------------------------------
/man/sim.swn.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/sim.swn.R
3 | \name{sim.swn}
4 | \alias{sim.swn}
5 | \title{Simulate Small-world Network}
6 | \usage{
7 | sim.swn(
8 | nodes,
9 | n,
10 | pos = 0.8,
11 | ran = c(0.3, 0.7),
12 | nei = 1,
13 | p = 0.5,
14 | corr = FALSE,
15 | replace = NULL,
16 | ordinal = FALSE,
17 | ordLevels = NULL
18 | )
19 | }
20 | \arguments{
21 | \item{nodes}{Number of nodes in the simulated network}
22 |
23 | \item{n}{Number of cases in the simulated dataset}
24 |
25 | \item{pos}{Proportion of positive correlations in the simulated network}
26 |
27 | \item{ran}{Range of correlations in the simulated network}
28 |
29 | \item{nei}{Adjusts the number of connections each node has to
30 | neighboring nodes (see \code{\link[igraph]{sample_smallworld}})}
31 |
32 | \item{p}{Adjusts the rewiring probability (default is .5).
33 | p > .5 rewires the simulated network closer to a random network.
34 | p < .5 rewires the simulated network closer to a lattice network}
35 |
36 | \item{corr}{Should the simulated network be a correlation network?
37 | Defaults to FALSE.
38 | Set to TRUE for a simulated correlation network}
39 |
40 | \item{replace}{If noise > 0, then should participants be sampled with replacement?
41 | Defaults to TRUE.
42 | Set to FALSE to not allow the potential for participants to be consecutively entered
43 | into the simulated dataset.}
44 |
45 | \item{ordinal}{Should simulated continuous data be converted to ordinal?
46 | Defaults to FALSE.
47 | Set to TRUE for simulated ordinal data}
48 |
49 | \item{ordLevels}{If ordinal = TRUE, then how many levels should be used?
50 | Defaults to NULL.
51 | Set to desired number of intervals (defaults to 5)}
52 | }
53 | \value{
54 | Returns a list containing:
55 |
56 | \item{simNetwork}{Adjacency matrix of the simulated network}
57 |
58 | \item{simData}{Simulated data from sim.correlation in the \code{psych} package
59 | based on the simulated network}
60 |
61 | \item{simRho}{Simulated correlation from sim.correlation in the \code{psych} package}
62 | }
63 | \description{
64 | Simulates a small-world network based on specified topological properties.
65 | Data will also be simulated based on the true network structure
66 | }
67 | \examples{
68 | #Continuous data
69 | sim.Norm <- sim.swn(25, 500, nei = 3)
70 |
71 | #Ordinal data
72 | sim.Likert <- sim.swn(25, 500, nei = 3, replace = TRUE, ordinal = TRUE, ordLevels = 5)
73 |
74 | #Dichotomous data
75 | sim.Binary <- sim.swn(25, 500, nei = 3, replace = TRUE, ordinal = TRUE, ordLevels = 2)
76 |
77 | }
78 | \references{
79 | Csardi, G., & Nepusz, T. (2006).
80 | The \emph{igraph} software package for complex network research.
81 | \emph{InterJournal, Complex Systems}, \emph{1695}, 1-9.
82 | }
83 | \author{
84 | Alexander Christensen
85 | }
86 |
--------------------------------------------------------------------------------
/man/smallworldness.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/smallworldness.R
3 | \name{smallworldness}
4 | \alias{smallworldness}
5 | \title{Small-worldness Measure}
6 | \usage{
7 | smallworldness(
8 | A,
9 | iter = 100,
10 | progBar = FALSE,
11 | method = c("HG", "rand", "TJHBL")
12 | )
13 | }
14 | \arguments{
15 | \item{A}{An adjacency matrix of network data}
16 |
17 | \item{iter}{Number of random (or lattice) networks to generate,
18 | which are used to calculate the mean random ASPL and CC (or lattice)}
19 |
20 | \item{progBar}{Defaults to \code{FALSE}.
21 | Set to \code{TRUE} to see progress bar}
22 |
23 | \item{method}{Defaults to \code{"HG"} (Humphries & Gurney, 2008).
24 | Set to \code{"rand"} for the CC to be calculated using a random network or
25 | set to \code{"TJHBL"} for (Telesford et al., 2011) where CC is calculated from a lattice network}
26 | }
27 | \value{
28 | Returns a list containing:
29 |
30 | \item{swm}{Small-worldness value}
31 |
32 | \item{rASPL}{Global average shortest path length from random network}
33 |
34 | \item{lrCCt}{When \code{"rand"}, clustering coefficient from a random network.
35 | When \code{"HG"}, transitivity from a random network.
36 | When \code{"TJHBL"}, clustering coefficient from a lattice network}
37 | }
38 | \description{
39 | Computes the small-worldness measure of a network
40 | }
41 | \details{
42 | For \code{"rand"}, values > 1 indicate a small-world network.
43 | For \code{"HG"}, values > 3 indicate a small-world network.
44 | For \code{"TJHBL"}, values near 0 indicate a small-world network,
45 | while < 0 indicates a more regular network and > 0 indicates a more random network
46 | }
47 | \examples{
48 | # Pearson's correlation only for CRAN checks
49 | A <- TMFG(neoOpen, normal = FALSE)$A
50 |
51 | \donttest{
52 | swmHG <- smallworldness(A, method="HG")
53 |
54 | swmRand <- smallworldness(A, method="rand")
55 |
56 | swmTJHBL <- smallworldness(A, method="TJHBL")}
57 |
58 | }
59 | \references{
60 | Humphries, M. D., & Gurney, K. (2008).
61 | Network 'small-world-ness': A quantitative method for determining canonical network equivalence.
62 | \emph{PLoS one}, \emph{3}, e0002051.
63 |
64 | Telesford, Q. K., Joyce, K. E., Hayasaka, S., Burdette, J. H., & Laurienti, P. J. (2011).
65 | The ubiquity of small-world networks.
66 | \emph{Brain Connectivity}, \emph{1}(5), 367-375.
67 | }
68 | \author{
69 | Alexander Christensen
70 | }
71 |
--------------------------------------------------------------------------------
/man/stable.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/stable.R
3 | \name{stable}
4 | \alias{stable}
5 | \title{Stabilizing Nodes}
6 | \usage{
7 | stable(
8 | A,
9 | comm = c("walktrap", "louvain"),
10 | cent = c("betweenness", "rspbc", "closeness", "strength", "degree", "hybrid"),
11 | absolute = TRUE,
12 | diagonal = 0,
13 | ...
14 | )
15 | }
16 | \arguments{
17 | \item{A}{An adjacency matrix of network data}
18 |
19 | \item{comm}{Can be a vector of community assignments or community detection algorithms
20 | (\code{"walktrap"} or \code{"louvain"}) can be used to determine the number of factors.
21 | Defaults to \code{"walktrap"}.
22 | Set to \code{"louvain"} for \code{\link[NetworkToolbox]{louvain}} community detection}
23 |
24 | \item{cent}{Centrality measure to be used.
25 | Defaults to \code{"strength"}.}
26 |
27 | \item{absolute}{Should network use absolute weights?
28 | Defaults to \code{TRUE}.
29 | Set to \code{FALSE} for signed weights}
30 |
31 | \item{diagonal}{Sets the diagonal values of the \code{A} input.
32 | Defaults to \code{0}}
33 |
34 | \item{...}{Additional arguments for \code{\link[igraph]{cluster_walktrap}}
35 | and \code{\link[NetworkToolbox]{louvain}} community detection algorithms}
36 | }
37 | \value{
38 | A matrix containing the within-community centrality value for each node
39 | }
40 | \description{
41 | Computes the within-community centrality for each node in the network
42 | }
43 | \examples{
44 | # Pearson's correlation only for CRAN checks
45 | A <- TMFG(neoOpen, normal = FALSE)$A
46 |
47 | stabilizing <- stable(A, comm = "walktrap")
48 |
49 | }
50 | \references{
51 | Blanken, T. F., Deserno, M. K., Dalege, J., Borsboom, D., Blanken, P., Kerkhof, G. A., & Cramer, A. O. (2018).
52 | The role of stabilizing and communicating symptoms given overlapping communities in psychopathology networks.
53 | \emph{Scientific Reports}, \emph{8}, 5854.
54 | }
55 | \author{
56 | Alexander Christensen
57 | }
58 |
--------------------------------------------------------------------------------
/man/strength.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/strength.R
3 | \name{strength}
4 | \alias{strength}
5 | \title{Node Strength}
6 | \usage{
7 | strength(A, absolute = TRUE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{absolute}{Should network use absolute weights?
13 | Defaults to \code{TRUE}.
14 | Set to \code{FALSE} for signed weights}
15 | }
16 | \value{
17 | A vector of strength values for each node in the network.
18 |
19 | If directed network, returns a list containing:
20 |
21 | \item{inStrength}{Strength of incoming edges (pointing to the node)}
22 |
23 | \item{outStrength}{Strength of outgoing edges (pointing away from the node)}
24 |
25 | \item{relInf}{Relative degree of incoming and outgoing edges.
26 | Positive values indicate more outgoing strength relative to incoming strength.
27 | Negative values indicate more incoming strength relative to outgoing strength}
28 | }
29 | \description{
30 | Computes strength of each node in a network
31 | }
32 | \examples{
33 | # Pearson's correlation only for CRAN checks
34 | A <- TMFG(neoOpen, normal = FALSE)$A
35 |
36 | str <- strength(A)
37 |
38 | #Directed network
39 | \dontrun{
40 | dep <- depend(neoOpen)
41 |
42 | Adep <- TMFG(dep, depend = TRUE)$A
43 |
44 | str <- strength(Adep)
45 | }
46 |
47 | }
48 | \references{
49 | Rubinov, M., & Sporns, O. (2010).
50 | Complex network measures of brain connectivity: Uses and interpretations.
51 | \emph{NeuroImage}, \emph{52} 1059-1069.
52 | }
53 | \author{
54 | Alexander Christensen
55 | }
56 |
--------------------------------------------------------------------------------
/man/threshold.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/threshold.R
3 | \name{threshold}
4 | \alias{threshold}
5 | \title{Threshold Network Estimation Methods}
6 | \usage{
7 | threshold(
8 | data,
9 | a,
10 | thresh = c("alpha", "adaptive", "bonferroni", "FDR", "proportional"),
11 | normal = FALSE,
12 | na.data = c("pairwise", "listwise", "fiml", "none"),
13 | ...
14 | )
15 | }
16 | \arguments{
17 | \item{data}{Can be a dataset or a correlation matrix}
18 |
19 | \item{a}{When \code{thresh = "alpha"}, \code{"adaptive"}, and \code{"bonferroni"}
20 | an \eqn{\alpha} threshold is applied (defaults to \code{.05}).
21 | For \code{"adaptive"}, beta (Type II error) is set to \eqn{\alpha*5} for a medium effect size (\emph{r} = .3).
22 | When \code{thresh = "FDR"}, a q-value threshold is applied (defaults to \code{.10}).
23 | When \code{thresh = "proportional"}, a density threshold is applied (defaults to \code{.15})}
24 |
25 | \item{thresh}{Sets threshold. Defaults to \code{"alpha"}.
26 | Set to any value 0> \emph{r} >1 to retain values greater than set value,
27 | \code{"adaptive"} for an \code{\link{adapt.a}} based on sample size (Perez & Pericchi, 2014),
28 | \code{"bonferroni"} for the bonferroni correction on alpha,
29 | \code{"FDR"} for local false discovery rate,
30 | and \code{"proportional"} for a fixed density of edges (keeps strongest correlations within density)}
31 |
32 | \item{normal}{Should data be transformed to a normal distribution?
33 | Defaults to FALSE.
34 | Data is not transformed to be normal.
35 | Set to TRUE if data should be transformed to be normal
36 | (computes correlations using the \link[qgraph]{cor_auto} function)}
37 |
38 | \item{na.data}{How should missing data be handled?
39 | For \code{"listwise"} deletion the \code{\link{na.omit}} function is applied.
40 | Set to \code{"fiml"} for Full Information Maximum Likelihood (\code{\link[psych]{corFiml}}).
41 | Full Information Maximum Likelihood is \strong{recommended} but time consuming}
42 |
43 | \item{...}{Additional arguments for \code{\link[fdrtool]{fdrtool}} and \code{\link[NetworkToolbox]{adapt.a}}}
44 | }
45 | \value{
46 | Returns a list containing:
47 |
48 | \item{A}{The filtered adjacency matrix}
49 |
50 | \item{r.cv}{The critical correlation value used to filter the network}
51 | }
52 | \description{
53 | Filters the network based on an r-value, alpha, adaptive alpha,
54 | bonferroni, false-discovery rate (FDR), or proportional density (fixed number of edges) value
55 | }
56 | \examples{
57 | threshnet<-threshold(neoOpen)
58 |
59 | alphanet<-threshold(neoOpen, thresh = "alpha", a = .05)
60 |
61 | bonnet<-threshold(neoOpen, thresh = "bonferroni", a = .05)
62 |
63 | FDRnet<-threshold(neoOpen, thresh = "FDR", a = .10)
64 |
65 | propnet<-threshold(neoOpen, thresh = "proportional", a = .15)
66 | }
67 | \references{
68 | Strimmer, K. (2008).
69 | fdrtool: A versatile R package for estimating local and tail area-based false discovery rates.
70 | \emph{Bioinformatics}, \emph{24}, 1461-1462.
71 | }
72 | \author{
73 | Alexander Christensen
74 | }
75 |
--------------------------------------------------------------------------------
/man/transitivity.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/transitivity.R
3 | \name{transitivity}
4 | \alias{transitivity}
5 | \title{Transitivity}
6 | \usage{
7 | transitivity(A, weighted = FALSE)
8 | }
9 | \arguments{
10 | \item{A}{An adjacency matrix of network data}
11 |
12 | \item{weighted}{Is the network weighted?
13 | Defaults to \code{FALSE}.
14 | Set to \code{TRUE} for a weighted measure of transitivity}
15 | }
16 | \value{
17 | Returns a value of transitivity
18 | }
19 | \description{
20 | Computes transitivity of a network
21 | }
22 | \examples{
23 | # Pearson's correlation only for CRAN checks
24 | A <- TMFG(neoOpen, normal = FALSE)$A
25 |
26 | trans <- transitivity(A, weighted=TRUE)
27 | }
28 | \references{
29 | Rubinov, M., & Sporns, O. (2010).
30 | Complex network measures of brain connectivity: Uses and interpretations.
31 | \emph{NeuroImage}, \emph{52}, 1059-1069.
32 | }
33 | \author{
34 | Alexander Christensen
35 | }
36 |
--------------------------------------------------------------------------------
/man/un.direct.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/un.direct.R
3 | \name{un.direct}
4 | \alias{un.direct}
5 | \title{Convert Directed Network to Undirected Network}
6 | \usage{
7 | un.direct(A, diagonal = 0)
8 | }
9 | \arguments{
10 | \item{A}{Matrix or data frame.
11 | Adjacency matrix (network matrix)}
12 |
13 | \item{diagonal}{Numeric.
14 | Number to be placed on the diagonal.
15 | Defaults to \code{0}}
16 | }
17 | \value{
18 | Returns a symmetric adjacency matrix
19 | }
20 | \description{
21 | Converts a directed network to an undirected network
22 | }
23 | \examples{
24 | # Pearson's correlation only for CRAN checks
25 | A <- TMFG(neoOpen, normal = FALSE)$A
26 |
27 | # create a directed network
28 | dir <- A * sample(c(0,1), size = length(A), replace = TRUE)
29 |
30 | # undirect the directed network
31 | undir <- un.direct(dir)
32 |
33 | }
34 | \author{
35 | Alexander Christensen
36 | }
37 |
--------------------------------------------------------------------------------