cox-stuart实现方法

2025-10-26 05:04:52

1、R语言代码

# 处理成为符号数据

  cox_test <- function(dat = customers) {

    n <- length(dat)

    c <- (n - 1)/2

    d <- rep(0, c)

    if (c %% 2 == 0) {                        # dat长度为偶数

      for (i in 1:c) {d[i] <- dat[c + i] - dat[i]}

    } else {                                  # dat长度为奇数时要去掉中间数

      dat <- dat[-(c + 1)]

      for (i in 1:c) {d[i] <- dat[c + i] - dat[i]}

    }

    d <- d[d != 0]

    binom.test(sum(d > 0), length(d), alt = 'less')

  }

  customers <- c(5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15)

  cox_test(dat = customers)

  

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢