首页 > 解决方案 > 为 cuzick 测试安装的软件包

问题描述

我应该为 cuzick 测试安装哪个软件包?我已经尝试过 PMCMRplus 和 install_github("raredd/rawr") 但我仍然找不到任何用于 cuzick 测试的包

标签: rinstall.packages

解决方案


cuzick = function(x,z,test.type=c("two.sided", "upper", "lower")) {
    test.type <- match.arg(test.type)
    N = length(z)
    n = unique(z)

    ranks=rank(x)

    T = sum(ranks*z)

    p = (table(z)/N)
    E_Z = sum(unique(z)*p)
    E_T = 0.5*N*(N+1)*E_Z

    Var_Z = sum(unique(z)^2*p) - E_Z^2
    Var_T = N^2*(N+1)/12*Var_Z

    Zscore = (T-E_T)/sqrt(Var_T)

    if(test.type == "two.sided") {
        pval = 2*pnorm(-abs(Zscore))
    } else if(test.type == "upper") {
        pval = pnorm(Zscore,lower.tail=F)
    } else  pval = pnorm(Zscore,lower.tail=T)

    out = data.frame(Zscore,pval,test.type)
    colnames(out) = c("Z","p","testType")
    return(out)
}

推荐阅读