R/inputM.R

Defines functions inputM

Documented in inputM

inputM <-
function(data){
        tau <- unique(c(data$L, data$R))
        tau <- sort(tau[is.finite(tau) & tau > 0])
        cols <- colnames(data)
        cols <- cols[startsWith(cols,'C')]
        m_out <- matrix(0, nrow = length(tau), ncol = nrow(data)*length(cols))
        rownames(m_out) <- tau
        colnames(m_out) <- c(sapply(cols, function(x) rep(x, nrow(data))))
        
        for(i in 1:nrow(data)){
            L <- data$L[i]
            R <- data$R[i]
            if(L<R){
                time_slots <- sum(tau > L & tau <= R)  
            }else{
                time_slots <- sum(tau == R)
            }
            
            possible_risks <- sum(data[i,cols])
            
            try <- 1/(possible_risks * time_slots)
            
            if(L<R){
                time_bucket <- which(tau > L & tau <= R)
            }else{
                time_bucket <- which(tau == R)
            }
            C_bucket <- (which(data[i,cols]==1)-1)*nrow(data)+i
            
            m_out[time_bucket, C_bucket] <- try
        }
        return(list(input = m_out, tau = tau))
    }

Try the sccr package in your browser

Any scripts or data that you put into this service are public.

sccr documentation built on Dec. 15, 2020, 5:11 p.m.