https://github.com/cran/emplik
Raw File
Tip revision: 0a13baf815199c799dedcf0559f4a52598d3f0fd authored by Mai Zhou on 13 August 2014, 00:00:00 UTC
version 0.9-9-5
Tip revision: 0a13baf
redistF.R
redistF <- function(y, d, Fdist) {
n <- length(d)
if ( length(y) != n ) stop("length of y and d must agree")
if ( any((d != 0) & (d !=1)) ) stop("d must be either 0 or 1")
if ( length(Fdist) != n ) stop("Fdist must have length n")
# Fdist must be a probability distribution
# the time vector is the ysort, and the prob mass is in Fdist

yorder <- order(y, -d)
ysort <- y[yorder]
dsort <- d[yorder]

WeightMat <- diag( rep(1, n) )

for (i in 1:(n-1)) 
     if ( dsort[i] == 0 ) {
           WeightMat[i, (i+1):n] <- Fdist[(i+1):n]/sum(Fdist[(i+1):n])
           WeightMat[i,i] <- 0
                          }

list(y=ysort, d=dsort, weight=WeightMat, ordY=yorder)
}
back to top