/
simY_frn.R
37 lines (34 loc) · 1.04 KB
/
simY_frn.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#' Simulate an relational matrix based on a fixed rank nomination scheme
#'
#' Simulate an relational matrix based on a fixed rank nomination scheme
#'
#'
#' @usage simY_frn(EZ, rho, odmax, YO)
#' @param EZ a square matrix giving the expected value of the latent Z matrix
#' @param rho dyadic correlation
#' @param odmax a scalar or vector giving the maximum number of nominations for
#' each node
#' @param YO a square matrix identifying where missing values should be
#' maintained
#' @return a square matrix, where higher values represent stronger
#' relationships
#' @author Peter Hoff
#' @export simY_frn
simY_frn <-
function(EZ,rho,odmax,YO=NULL)
{
if(length(odmax)==1) { odmax<-rep(odmax,nrow(EZ)) }
ZS<-simZ(EZ,rho)
diag(ZS)<- -Inf
if(!is.null(YO)) { ZS[is.na(YO)]<- -Inf }
YS<-ZS*0
for(i in 1:nrow(EZ))
{
rs<-rank(ZS[i,]) - (nrow(EZ)-odmax[i])
YS[i,]<-rs*(rs>0)*(ZS[i,]>0)
YS[i,YS[i,]>0 ] <- match( YS[i,YS[i,]>0 ] ,sort(unique(YS[i,YS[i,]>0 ])))
}
diag(YS)<-NA
if(!is.null(YO)) { YS[is.na(YO)]<- NA }
YS
}