R Under development (unstable) (2024-02-18 r85939 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # File tests/normal.R in package latentnet, part of the > # Statnet suite of packages for network analysis, https://statnet.org . > # > # This software is distributed under the GPL-3 license. It is free, > # open source, and has the attribution requirements (GPL Section 7) at > # https://statnet.org/attribution . > # > # Copyright 2003-2024 Statnet Commons > ################################################################################ > library(statnet.common) Attaching package: 'statnet.common' The following objects are masked from 'package:base': attr, order > opttest({ + library(latentnet) + n<-20 + + y.var<-1/16 + y.var.prior<-4*y.var + + y<-as.network(matrix(1,n,n),dir=TRUE) + + cat("Euclidean:\n") + + Z<-rbind(cbind(rnorm(n/2,3),rnorm(n/2,3)), + cbind(rnorm(n/2,-3),rnorm(n/2,-3))) + + dm<--as.matrix(dist(Z)) + + ym<-rnorm(n*n,2+dm,sqrt(y.var)) + + set.edge.value(y,"v",ym) + image(as.matrix(y,a="v",m="a")) + y.fit<-ergmm(y~euclidean(d=2,G=2),response="v",family="normal",fam.par=list(prior.var=y.var.prior,prior.var.df=2),verbose=TRUE) + + Z.mkl<-plot(y.fit,Z.ref=Z) + points(Z,pch=5) + cat("Mean squared difference:",sum((Z.mkl-Z)^2),"\n") + + + # Simulate from the fit. + y.sim <- simulate(y.fit, nsim=1) + + cat("Bilinear:\n") + + dm<-tcrossprod(Z) + + ym<-rnorm(n*n,2+dm,sqrt(y.var)) + + set.edge.value(y,"v",ym) + image(as.matrix(y,a="v",m="a")) + y.fit<-ergmm(y~bilinear(d=2,G=2),response="v",family="normal",fam.par=list(prior.var=y.var.prior,prior.var.df=2),verbose=TRUE) + + Z.mkl<-plot(y.fit,Z.ref=Z) + points(Z,pch=5) + cat("Mean squared difference:",sum((Z.mkl-Z)^2),"\n") + + + cat("Squared Euclidean:\n") + + dm<--as.matrix(dist(Z))^2 + + ym<-rnorm(n*n,2+dm,sqrt(y.var)) + + set.edge.value(y,"v",ym) + image(as.matrix(y,a="v",m="a")) + y.fit<-ergmm(y~euclidean2(d=2,G=2),response="v",family="normal",fam.par=list(prior.var=y.var.prior,prior.var.df=2),verbose=TRUE) + + Z.mkl<-plot(y.fit,Z.ref=Z) + points(Z,pch=5) + cat("Mean squared difference:",sum((Z.mkl-Z)^2),"\n") + + + # Simulate from the fit. + y.sim <- simulate(y.fit, nsim=1) + + cat("No latent space:\n") + + ym<-rnorm(n*n,0,sqrt(y.var)) + set.edge.value(y,"v",ym) + image(as.matrix(y,a="v",m="a")) + y.fit<-ergmm(y~1,response="v",family="normal",fam.par=list(prior.var=y.var.prior,prior.var.df=2),verbose=TRUE) + summary(y.fit) + + + },"Normal response variable") Normal response variable test(s) skipped. Set ENABLE_statnet_TESTS environment variable to run. > > proc.time() user system elapsed 0.32 0.06 0.37