Code - Note 1

Method of Moments Estimator for models on trees

Stefka Asenova

2021-12-20

Load the data.

data("SeineData", package = "gremes")
head(Seine)
#>       Paris      Meaux      Melun   Nemours     Sens
#> 1  2.124338  -1.736640  9.0907845 0.5187825 14.26062
#> 2  9.646991   2.632994  8.7440743 0.6394548 15.47040
#> 3 19.172176  21.584171  9.1692941 2.1770178 15.26537
#> 4  5.357301 -14.759895 -0.4941262 1.5233623 13.47500
#> 5  6.044298 -20.772417  1.0182723 2.1690976 13.39804
#> 6  3.805912 -40.779572 -7.3982814 1.2666607 14.60144

Generate the graph and name the nodes. Note that assigning names to nodes is crucial. The names of the nodes should correspond to the names of the columns in the dataset.

seg<- graph(c(1,2,
              2,3,
              2,4,
              4,5,
              5,6,
              5,7), directed = FALSE)
name_stat<- c("Paris", "2", "Meaux", "Melun", "5", "Nemours", "Sens")
seg<- set.vertex.attribute(seg, "name", V(seg), name_stat) 

Create the subsets. In the first step subsets are used for local estimation of the edge weights, as the second step the estimates are combined through a minimal distance procedeure to produce unique estimates.

subs<- Neighborhood()
subs<- subset(subs, 2, seg, U_bar=c("2", "5"))
subs 
#> $value
#> $value$Paris
#> [1] "Paris" "2"     "Meaux" "Melun"
#> 
#> $value$Meaux
#> [1] "Meaux" "2"     "Paris" "Melun"
#> 
#> $value$Melun
#> [1] "Melun"   "2"       "5"       "Paris"   "Meaux"   "Nemours" "Sens"   
#> 
#> $value$Nemours
#> [1] "Nemours" "5"       "Melun"   "Sens"   
#> 
#> $value$Sens
#> [1] "Sens"    "5"       "Melun"   "Nemours"
#> 
#> 
#> $root
#> [1] "Paris"   "Meaux"   "Melun"   "Nemours" "Sens"   
#> 
#> attr(,"class")
#> [1] "list"         "RootDepSet"   "Neighborhood"

Estimate using method of moment estimator.

mme<- MME(seg)
#> From HRMnetwork: Edges have been assigned names
mme<- estimate(mme, Seine, subs,  k_ratio=0.2)
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From setRootDepSet.RootDepSet: The order of the subset must correspond to the
#>             order of its corresponding root
#> From setParams.HRMtree: Names have been attributed to the vector 'value' in the order corresponding to the order of the edges: The fist element has the name of the first edge, the second element the name of the second edge, etc.
#> From setParams.HRMtree: The parameters have been attached to the edges according to their names

The messages are informative. They inform you about certain things along the estimation process, but as long as they do not stop the estimation they are not errors.

The estimates are squares of the parameters, hence take the square root.

sqrt(mme$depParams)
#>        e1        e2        e3        e4        e5        e6 
#> 0.3833844 0.9491690 0.5914040 0.6287704 1.0034604 0.6162232