Latent Space Models

Download R source file
            
              library(amen)

data(IR90s)
gdp<-IR90s$nodevars[,2]
topgdp<-which(gdp>=sort(gdp,decreasing=TRUE)[30] )
Y_nrm<-log( IR90s$dyadvars[topgdp,topgdp,2] + 1 )

Y_nrm[1:5,1:5]

fit_SRM_nrm<-ame(Y_nrm)

dimnames(IR90s$nodevars)[[2]]
Xn_nrm<-IR90s$nodevars[topgdp,]
Xn_nrm[,1:2]<-log(Xn_nrm[,1:2])

dimnames(IR90s$dyadvars)[[3]]
Xd_nrm<-IR90s$dyadvars[topgdp,topgdp,c(1,3,4,5)]
Xd_nrm[,,3]<-log(Xd_nrm[,,3])

fit_srrm_nrm<-ame(Y_nrm,Xd=Xd_nrm,Xr=Xn_nrm,Xc=Xn_nrm)

fit_rm_nrm<-ame(Y_nrm,Xd=Xd_nrm,Xr=Xn_nrm,Xc=Xn_nrm,
	rvar=FALSE,
	cvar=FALSE,
	dcor=FALSE)

fit_ame2_nrm<-ame(Y_nrm,Xd_nrm,Xn_nrm,Xn_nrm,R=2)

data(lazegalaw)
##data on friendship ties between 71 members of a law firm
Y_bin<-lazegalaw$Y[,,2]
Xd_bin<-lazegalaw$Y[,,-2]
Xn_bin<-lazegalaw$X

dimnames(Xd)[[3]]
dimnames(Xn)[[2]]

fit_SRM_bin<-ame(Y_bin,model="bin")
fit_SRG_bin<-ame(Y_bin,model="bin",rvar=FALSE,cvar=FALSE,dcor=FALSE)

Xno_bin<-Xn_bin[,c(1,2,4,5,6)]
fit_SRRM_bin<-ame(Y_bin, Xd=Xd_bin, Xr=Xno_bin, Xc=Xno_bin, 
	model="bin")

fit_AME_bin<-ame(Y_bin, Xd=Xd_bin[,,2], R=3, model="bin")

data(sheep)
##relations between 28 female bighorn sheep.
##y_ij records the number of times sheep i dominated sheep j
Y_ord<-sheep$dom

x<-sheep$age - mean(sheep$age)
Xd_ord<-outer(x,x)
Xn_ord<-cbind(x,x^2) ; colnames(Xn_ord)<-c("age","age2")
fit_ord<-ame(Y_ord, Xd_ord, Xn_ord, Xn_ord, model="ord")