R/sbinom.R

Defines functions `sbinom`

`sbinom` <-
function(x) {
    if (ncol(x) > 2) {
        admisc::stopError("The table has more than two columns.")
    }
    
    if (!is.numeric(x[, 1])) {
        admisc::stopError("The first column should be numeric.")
    }
    
    if (!is.numeric(x[, 2])) {
        admisc::stopError("The second column should be numeric.")
    }
    
    if (sum(x[, 2] != 1)) {
        px <- proportions(x[, 2])
    } else {
        px <- x[, 2]
    }
    
    return(sqrt(sum((x[, 1] - sum(x[, 1]*px))^2*px)))
}
dusadrian/statistics documentation built on Jan. 26, 2023, 11:55 p.m.