Code - Note 3

Extremal Coefficients Estimator for models on trees

Stefka Asenova

2023-02-11

library(gremes)

Load the data.

#load("~/gremes/data/SeineData.RData")
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. 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) # 

Extract the nodes for which we do not observe realizations.

tobj<- Tree(seg, Seine)
#> From validate.Network: Edges have been assigned names
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: Edges have been assigned names
#> From validate.Network: There are nodes with latent variables
Uc<- getNoDataNodes(tobj)

Alternatively just do it manually.

Uc<- c("2", "5")

Create the set of coordinates, in this case only vectors with two non-zero entries.

tup<- Tuples()
x<- rep(1,5)
names(x)<- getNodesWithData(tobj)
tup<- evalPoints(tup, tobj, x)

Estimate ECE Version 1

eks<- EKS(seg)
#> From HRMnetwork: Edges have been assigned names
eks<-estimate(eks, Seine, tup, k_ratio=0.2)
#> From validate.Network: There are nodes with latent variables
#> From validate.Network: There are nodes with latent variables
#> 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

Estimate ECE Version 2

To apply ECE Version 2 we need to create subsets for local estimation. Create the subsets.

subs<- Neighborhood()
subs<- subset(subs, 2, seg, Uc) # neighborhood of level two

Call the estimation method.

eks_part<- EKS_part(seg)
#> From HRMnetwork: Edges have been assigned names
eks_part<- suppressMessages(estimate(eks_part, Seine, subs, k_ratio=0.2, xx=x))

Because the method gives many messages we suppress them. The messages are informative. They inform you about certain things but as long as they do not stop the estimation they are not errors.

Compare estimates from the two versions.

eks$depParams
#>        e1        e2        e3        e4        e5        e6 
#> 0.6998687 1.2696199 0.2228986 0.5155293 1.1730987 0.9649355
eks_part$depParams
#>        e1        e2        e3        e4        e5        e6 
#> 0.6430240 1.2985508 0.4067386 0.6610828 1.1893985 0.9446311