Version: 1.0.1
Type: Package
Title: Multiple Random Dot Product Graphs
Description: Fits the Multiple Random Dot Product Graph Model and performs a test for whether two networks come from the same distribution. Both methods are proposed in Nielsen, A.M., Witten, D., (2018) "The Multiple Random Dot Product Graph Model", arXiv preprint <doi:10.48550/arXiv.1811.12172> (Submitted to Journal of Computational and Graphical Statistics).
License: GPL-2
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
NeedsCompilation: no
Packaged: 2018-11-30 16:37:58 UTC; agni
Author: Agnes Martine Nielsen [aut, cre], Daniela Witten [aut]
Maintainer: Agnes Martine Nielsen <agni@dtu.dk>
Repository: CRAN
Date/Publication: 2018-12-09 13:40:03 UTC

Calculates positive semi-definite part of a matrix

Description

aplusfun calculates the positive semidefinite part of a matrix

Usage

aplusfun(Amat)

Arguments

Amat

A symmetric matrix

Value

Returns positive semidefinite part of Amat

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)


calculateLRstat calculates the likelihood ratio statistic

Description

calculateLRstat calculates the likelihood ratio statistic

Usage

calculateLRstat(A, null, alt)

Arguments

A

List of symmetric A matrices

null

Model fitted under the null

alt

Model fitted under the alternative

Value

Value of the likelihood ratio statistic

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)


calculateobjfun calculates the objective function

Description

calculateobjfun calculates the objective function

Usage

calculateobjfun(Aplus, Lambda, U)

Arguments

Aplus

List of positive semi definite part of A matrices

Lambda

List of Lambdas

U

U matrix that contains the othogonal vectors

Value

Returns the value of the objective function, sum(||Aplus-U Lambda U^T||_F^2)

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)


Fitting Multiple Random Dot Product Graphs

Description

multiRDPG is used to fit Multiple Random Dot Product Graphs from a set of adjacency matrices.

Usage

multiRDPG(A, d, maxiter = 100, tol = 1e-06)

Arguments

A

List of adjacency matrices representing graphs. Each matrix must be symmetric. All matrices of the same size n x n.

d

Dimension of latent space. d<= n.

maxiter

Maximal number of iterations. Default is 100.

tol

Tolerance for update of the objective function. Default is 1e-6.

Value

Returns a list of the following:

U Matrix of the joint vectors. n x d.
Lambda List of diagonal matrices. One for each graph. d x d.
Converged Represent of the algorithm converged. 1 if converged, 0 if not.
iter Number of iterations
maxiter Maximal number of iterations.Default is 100.
objfun Value of the objective function. sum_k ||A^k - U Lambda U^T||_F^2

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG_test

Examples

#simulate data
U <- matrix(0, nrow=20, ncol=3)
U[,1] <- 1/sqrt(20)
U[,2] <- rep(c(1,-1), 10)/sqrt(20)
U[,3] <- rep(c(1,1,-1,-1), 5)/sqrt(20)

L<-list(diag(c(11,6,2)),diag(c(15,4,1)))
A <- list()
for(i in 1:2){
  P <- U%*%L[[i]]%*%t(U)
  A[[i]] <-apply(P,c(1,2),function(x){rbinom(1,1,x)})
  A[[i]][lower.tri(A[[i]])]<-t(A[[i]])[lower.tri(A[[i]])]
}

#fit model
multiRDPG(A,3)



Performs test based on Multiple Random Dot Product Graph

Description

multiRDPG_test calculates the likelihood ratio test for whether a set of graphs comes from the same disribution.

Usage

multiRDPG_test(A, d, maxiter = 100, tol = 1e-06, B = 1000)

Arguments

A

List of symmetric A matrices

d

Dimension of the latent space

maxiter

Maximum number of iterations in the fit of multiRDPG. Default is 100.

tol

Tolerance for the step in the objective function in multiRDPG. Default is 1e-6.

B

Number of permutation iterations. Default is 1000.

Value

Returns a list of the following elements:

pvalue Estimated p-values
Tval Value of the test statistic
Tstar Vector of the test statistic for each permutation iteration
nullmodel Model fit under the null
altmodel Modelfit under the alternative

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG

Examples

#simulate data
U <- matrix(0, nrow=20, ncol=3)
U[,1] <- 1/sqrt(20)
U[,2] <- rep(c(1,-1), 10)/sqrt(20)
U[,3] <- rep(c(1,1,-1,-1), 5)/sqrt(20)

L<-list(diag(c(11,6,2)),diag(c(15,4,1)))
A <- list()
for(i in 1:2){
  P <- U%*%L[[i]]%*%t(U)
  A[[i]] <-apply(P,c(1,2),function(x){rbinom(1,1,x)})
  A[[i]][lower.tri(A[[i]])]<-t(A[[i]])[lower.tri(A[[i]])]
}

#perform test
multiRDPG_test(A,3,B=100)



nullestimation calculates the estimation under the null hypothesis

Description

nullestimation calculates the estimation under the null hypothesis

Usage

nullestimation(A, d)

Arguments

A

List of symmetric A matrices

d

Dimension of the latent space

Value

Returns a list of the following

U The common latent space vectors. U in R^n x d
Lambda List of Lambdas. Each is a positive diagonal matrix of size d x d.

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG

Examples

#simulate data
U <- matrix(0, nrow=20, ncol=3)
U[,1] <- 1/sqrt(20)
U[,2] <- rep(c(1,-1), 10)/sqrt(20)
U[,3] <- rep(c(1,1,-1,-1), 5)/sqrt(20)

L<-list(diag(c(11,6,2)),diag(c(15,4,1)))
A <- list()
for(i in 1:2){
  P <- U%*%L[[i]]%*%t(U)
  A[[i]] <-apply(P,c(1,2),function(x){rbinom(1,1,x)})
  A[[i]][lower.tri(A[[i]])]<-t(A[[i]])[lower.tri(A[[i]])]
}

#fit model
nullestimation(A,3)



Plots object from multiRDPG

Description

Plots object from multiRDPG

Usage

## S3 method for class 'multiRDPGfit'
plot(x, ...)

Arguments

x

multiRDPGfit object from function multiRDPG

...

further arguments passed to or from other methods

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG


Plots object from multiRDPG_test

Description

Plots histogram of permutation test statistics and indicates test statistic value with red line.

Usage

## S3 method for class 'multiRDPGtest'
plot(x, ...)

Arguments

x

multiRDPGtest object from function multiRDPG_test

...

further arguments passed to or from other methods

Details

Red line indicates the value of the test statistics with a red line.

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG_test


Print object from multiRDPG

Description

Print object from multiRDPG

Usage

## S3 method for class 'multiRDPGfit'
print(x, ...)

Arguments

x

multiRDPGfit object from function multiRDPG

...

further arguments passed to or from other methods

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG


Print object from multiRDPG_test

Description

Print object from multiRDPG_test

Usage

## S3 method for class 'multiRDPGtest'
print(x, ...)

Arguments

x

multiRDPGtest object from function multiRDPG_test

...

further arguments passed to or from other methods

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)

See Also

multiRDPG_test


swapA swaps the elements of A at random

Description

swapA swaps the elements of A at random

Usage

swapA(A)

Arguments

A

List of symmetric A matrices

Value

Returns list of matrices with elements swapped

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)


updateL updates all Lambda

Description

updateL updates all Lambda

Usage

updateL(Aplus, U, d)

Arguments

Aplus

List of positive definite parts of A

U

Current U matrix

d

Dimension of latent space

Value

Returns list of updated Lambdas

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)


updateU calculates the U update

Description

updateU calculates the U update

Usage

updateU(AA, Lambda, Uold)

Arguments

AA

All Aplus matrices column binded

Lambda

List of Lambdas

Uold

U found in past iteration

Value

Returns updated U

Author(s)

Agnes Martine Nielsen (agni@dtu.dk)