mstree                 package:spdep                 R Documentation

_F_i_n_d _t_h_e _m_i_n_i_m_a_l _s_p_a_n_n_i_n_g _t_r_e_e

_D_e_s_c_r_i_p_t_i_o_n:

     The minimal spanning tree is a connected graph with n nodes and
     n-1 edges. This is a smaller class of possible partitions of a
     graph by pruning edges with high dissimilarity. If one edge is
     removed, the graph is partioned in two unconnected subgraphs. This
     function implements the algorithm due to Prim (1987).

_U_s_a_g_e:

     mstree(nbw, ini = NULL)

_A_r_g_u_m_e_n_t_s:

     nbw: An object of 'listw' class returned by 'nb2listw' function.
          See this help for details.

     ini: The initial node in the minimal spanning tree.

_D_e_t_a_i_l_s:

     The minimum spanning tree algorithm.

     Input a connected graph.

     Begin a empty set of nodes.

     Add an arbitrary note in this set.

     While are nodes not in the set, find a minimum cost edge
     connecting a node in the set and a node out of the set and add
     this node in the set.

     The set of edges is a minimum spanning tree.

_V_a_l_u_e:

     A matrix with n-1 rows and tree columns. Each row is two nodes and
     the cost, i. e. the edge and it cost.

_A_u_t_h_o_r(_s):

     Renato M. Assuncao and Elias T. Krainski

_R_e_f_e_r_e_n_c_e_s:

     R. C. Prim (1957) Shortest connection networks and some
     generalisations. In: Bell System Technical Journal, 36, pp.
     1389-1401

_E_x_a_m_p_l_e_s:

     ### loading data
     bh <- readShapePoly(system.file("etc/shapes/bhicv.shp",
           package="spdep")[1])
     ### data padronized
     dpad <- data.frame(scale(bh@data[,5:8]))

     ### neighboorhod list 
     bh.nb <- poly2nb(bh)

     ### calculing costs
     lcosts <- nbcosts(bh.nb, dpad)

     ### making listw
     nb.w <- nb2listw(bh.nb, lcosts, style="B")

     ### find a minimum spanning tree
     system.time(mst.bh <- mstree(nb.w,5))

     dim(mst.bh)

     head(mst.bh)
     tail(mst.bh)

     ### the mstree plot
     par(mar=c(0,0,0,0))
     plot(mst.bh, coordinates(bh), col=2, 
          cex.lab=.7, cex.circles=0.035, fg="blue")
     plot(bh, border=gray(.5), add=TRUE)

