Skip to content

Commit

Permalink
Fixes for LFix and LRan summations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gtikhonov committed Apr 10, 2024
1 parent fc9ae6e commit 366204d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 15 deletions.
5 changes: 1 addition & 4 deletions R/computeInitialParameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ computeInitialParameters = function(hM, initPar, computeZ=TRUE){
LRan[[r]] = LRan[[r]] + (Eta[[r]][hM$Pi[,r],,drop=FALSE]*hM$rL[[r]]$x[as.character(hM$dfPi[,r]),r]) %*% Lambda[[r]][,,k]
}
}
if(hM$nr > 0){
Z = LFix + Reduce("+", LRan)
} else
Z = LFix
Z = Reduce("+", c(list(LFix), LRan))

if(computeZ){
Z = updateZ(Y=hM$Y,Z=Z,Beta=Beta,iSigma=sigma^-1,Eta=Eta,Lambda=Lambda, Loff=hM$Loff,X=XScaled,Pi=hM$Pi,dfPi=hM$dfPi,distr=hM$distr,rL=hM$rL)
Expand Down
5 changes: 1 addition & 4 deletions R/computeWAIC.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ computeWAIC = function(hM, ghN=11, byColumn=FALSE){
LRan[[r]] = LRan[[r]] + (Eta[[r]][Pi[,r],]*rL[[r]]$x[as.character(dfPi[,r]),k]) %*% Lambda[[r]][,,k]
}
}
if(nr > 0){
E = LFix + Reduce("+", LRan)
} else
E = LFix
E = Reduce("+", c(list(LFix), LRan))

indNA = is.na(Y)
std = matrix(sigma^-0.5,ny,ns,byrow=TRUE)
Expand Down
4 changes: 2 additions & 2 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ get1prediction <-
LRan[[r]] = LRan[[r]] + (Eta[[r]][as.character(dfPiNew[,r]),]*rL[[r]]$x[as.character(dfPiNew[,r]),k]) %*% sam$Lambda[[r]][,,k]
}
}
L = Reduce("+", c(LFix, LRan))
L = Reduce("+", c(list(LFix), LRan))
if(!is.null(Loff)) L = L + Loff

## predict can be slow with Yc and especially with high mcmcStep
Expand Down Expand Up @@ -294,7 +294,7 @@ get1prediction <-
sam$Lambda[[r]][,,k]
}
}
if(object$nr > 0){L = LFix + Reduce("+", LRan)} else L = LFix
L = Reduce("+", c(list(LFix), LRan))
}
if(!expected){
Z = L + matrix(sqrt(sam$sigma),nrow(L),object$ns,byrow=TRUE) * matrix(rnorm(nrow(L)*object$ns),nrow(L),object$ns)
Expand Down
2 changes: 1 addition & 1 deletion R/updateBetaSel.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ updateBetaSel = function(Z,XSelect, BetaSel, Beta, iSigma,
LFix = matrix(NA,ny,ns)
for(j in 1:ns)
LFix[,j] = X[[j]]%*%Beta[,j]
E = Reduce("+", c(LFix,LRan))
E = Reduce("+", c(list(LFix), LRan))
if(!is.null(Loff)) E = E + Loff

ll = matrix(NA,ny,ns)
Expand Down
2 changes: 1 addition & 1 deletion R/updateEta.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ updateEta = function(Y,Z,Beta,iSigma,Eta,Lambda,Alpha, rLPar, Loff,X,Pi,dfPi,rL)
}
for(r in seq_len(nr)){
rnames=rownames(Eta[[r]])
S = Z - Reduce("+", c(LFix,LRan[setdiff(1:nr, r)]))
S = Z - Reduce("+", c(list(LFix), LRan[setdiff(1:nr,r)]))
if(!is.null(Loff)) S = S - Loff

lambda = Lambda[[r]]
Expand Down
2 changes: 1 addition & 1 deletion R/updateInvSigma.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ updateInvSigma = function(Y,Z,Beta,iSigma,Eta,Lambda, distr,Loff,X,Pi,dfPi,rL, a
LRan[[r]] = LRan[[r]] + (Eta[[r]][Pi[,r],]*rL[[r]]$x[as.character(dfPi[,r]),k]) %*% Lambda[[r]][,,k]
}
}
Eps = Z - Reduce("+", c(LFix,LRan))
Eps = Z - Reduce("+", c(list(LFix), LRan))
if(!is.null(Loff)) Eps = Eps - Loff

Yx = !is.na(Y)
Expand Down
2 changes: 1 addition & 1 deletion R/updateZ.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ updateZ = function(Y,Z,Beta,iSigma,Eta,Lambda, Loff,X,Pi,dfPi,distr,rL, ind){
LRan[[r]] = LRan[[r]] + (Eta[[r]][Pi[,r],]*rL[[r]]$x[as.character(dfPi[,r]),k]) %*% Lambda[[r]][,,k]
}
}
E = Reduce("+", c(LFix,LRan))
E = Reduce("+", c(list(LFix), LRan))
if(!is.null(Loff)) E = E + Loff

Z = matrix(NA,ny,ns)
Expand Down
2 changes: 1 addition & 1 deletion R/updatewRRR.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ updatewRRR = function(Z,Beta,iSigma,Eta,Lambda, Loff,X1A,XRRR,Pi,dfPi,rL,PsiRRR,
LRan[[r]] = LRan[[r]] + (Eta[[r]][Pi[,r],]*rL[[r]]$x[as.character(dfPi[,r]),r]) %*% Lambda[[r]][,,k]
}
}
S = Z - Reduce("+", c(LFix,LRan))
S = Z - Reduce("+", c(list(LFix), LRan))
if(!is.null(Loff)) S = S - Loff

A1 = BetaRRR%*%diag(iSigma,nrow = length(iSigma))%*%t(BetaRRR)
Expand Down

0 comments on commit 366204d

Please sign in to comment.