lasso罚极大似然

Posted by ccsong on October 10, 2016

图模型——罚极大似然

估计图结构的方法也有很多,这里只介绍罚极大似然的方法。图结构估计得常用假设是数据来自正态分布,把投票数据用正态分布处理。

data

  • R数据下载——数据中包含三个矩阵(数据来自http://www.senate.gov)。
  • idList矩阵为参议员信息。每行对应一个参议员。5列分别对应:议员id,last name, first name, state, party(Democrat, Republican or Independent)
  • bilInfo为投票议案信息(bil info)。每行对应一项议案信息,4列分别为:议案编号、投票时间、议案描述、投票结果。
  • voteMatrix矩阵为投票信息,每行对应bilInfo的议案,每列对于idList的一个议员。若voteMatrix的第i行第j列数值为1,表示议员j对议案i投了赞成票;-1表示反对票;NA表示未投票。
library(spaceExt)
library(igraph)
load("~/Rworkfile/learning/senate.RData")
#移除投票缺失较多的议员
sel=which(!(colSums(is.na(voteMatrix))>100))
partyD=as.numeric(idList[sel,5]=="D")
partyI=as.numeric(idList[sel,5]=="ID" | idList[sel,5]=="I")
#用spaceExt做计算
res=glasso.miss(voteMatrix[,sel],20,rho=0.1,penalize.diagonal=FALSE)
#计算偏相关系数矩阵
p=-res$wi
d=1/sqrt(diag(res$wi))
p=diag(d)%*%p%*%diag(d)
diag(p)=0
#igraph包生成图模型、作图
g=graph.adjacency((p>(0.055)),mode="undirected",diag=F)
V(g)$color=(partyD+2+partyI*2)
V(g)$label=idList[sel,3]
par(mar=c(0,0,0,0))
plot(g,layout=layout.fruchterman.reingold, edge.color=grey(0.5),vertex.size=10)


Creative Commons License
This work is licensed under a CC A-S 4.0 International License.