R/getpvalClassif.R

Defines functions getpvalClassif

getpvalClassif <-
function(x,y, nsim=500, test="normal"){
    if(is.function( test)){
        pval <- test(x,y)
    }else{
        if(test!="normal"){
            mud <- mean(x)-mean(y)
            cx <- c(x,y)
            ci <- c(rep(1,length(x)),rep(2,length(y)))
            muds <- numeric(nsim)
            for (sim in 1:nsim){
                ind <- sample( 1:length(cx),length(cx),replace=TRUE)
                muds[sim] <- mean(cx[ind[ ci[ind]==1]])-mean(cx[ind[ci[ind]==2]])
            }
            pval <- 2*(1-pt( abs(mud)/ sd(muds),df=nsim))
        }else{
            pval <- t.test(x,y)$p.value
        }
    }
    return(  pval  )
}

Try the InvariantCausalPrediction package in your browser

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

InvariantCausalPrediction documentation built on Nov. 10, 2019, 5:06 p.m.