cox-stuart实现方法

时间:2026-02-16 05:13:15

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)

  

© 2026 途途旅游
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com