R/Measure.R2S.R

Defines functions Measure.R2S

Documented in Measure.R2S

Measure.R2S <- function(biloci, struc, na.presence = TRUE) {
    CALC  <- TRUE
    M.r2s <- NA
    
    if (na.presence) {
        if (any(is.na(biloci))) {
            ligne <- na.action(na.omit(biloci))
            # less than 5 non-missing data
            CALC <- (length(ligne) <= (nrow(biloci) - 5))
            if (CALC) {
                biloci <- biloci[-ligne, ]
                struc <- struc[-ligne, ]
            }
        }
    }
    
    if (CALC) {
        sig_biloci			<-	var(biloci)
        sig_struc			<-	var(struc)
        sig_struc_inv		<-   Inv.proj.matrix.sdp(sig_struc)
        sig_biloci_struc	<-	cov(biloci, struc)
        sig_struc_biloci	<-	t(sig_biloci_struc)
        SIG					<-	sig_biloci - (sig_biloci_struc %*% sig_struc_inv %*% sig_struc_biloci)
        ifelse ((SIG[1, 1] < 0.0000001) | (SIG[2, 2] < 0.0000001),
                M.r2s <- 0,
                M.r2s <- (SIG[1, 2])^2 / (SIG[1, 1] * SIG[2, 2]))
        as.numeric(M.r2s)
    }
    
    M.r2s
}

Try the LDcorSV package in your browser

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

LDcorSV documentation built on Aug. 26, 2020, 9:06 a.m.