R语言如何查看函数源码[例:wilcox.test]

本文介绍了如何在R语言中查看函数源码,以`wilcox.test`为例,详细讲解了查看过程。
摘要由CSDN通过智能技术生成

R语言如何查看函数源码[例:wilcox.test]

命令

## 查看源码
>stats:::待查看的对象

以wilcox.test为例

## 查看wilcox.test的源码
>stats:::wilcox.test#命令行
function (x, ...) 
UseMethod("wilcox.test")
<bytecode: 0x0000024da5b4a4f0>
<environment: namespace:stats>

> stats:::wilcox.test.default#命令行
function (x, y = NULL, alternative = c("two.sided", "less", 
    "greater"), mu = 0, paired = FALSE, exact = NULL, correct = TRUE, 
    conf.int = FALSE, conf.level = 0.95, ...) 
{
    alternative <- match.arg(alternative)
    if (!missing(mu) && ((length(mu) > 1L) || !is.finite(mu))) 
        stop("'mu' must be a single number")
    if (conf.int) {
        if (!((length(conf.level) == 1L) && is.finite(conf.level) && 
            (conf.level > 0) && (conf.level < 1))) 
            stop("'conf.level' must be a single number between 0 and 1")
    }
    if (!is.numeric(x)) 
        stop("'x' must be numeric")
    if (!is.null(y)) {
        if (!is.numeric(y)) 
            stop("'y' must be numeric")
        DNAME <- paste(deparse(substitute(x)), "and", deparse(substitute(y)))
        if (paired) {
            if (length(x) != length(y)) 
                stop("'x' and 'y' must have the same length")
            OK <- complete.cases(x, y)
            x <- x[OK] - y[OK]
            y <- NULL
        }
        else {
            x <- x[is.finite(x)]
            y <- y[is.finite(y)]
        }
    }
    else {
        DNAME <- deparse(substitute(x))
        if (paired) 
            stop("'y' is missing for paired test")
        x <- x[is.finite(x)]
    }
    if (length(x) < 1L) 
        stop("not enough (finite) 'x' observations")
    CORRECTION <- 0
    if (is.null(y)) {
        METHOD <- "Wilcoxon signed rank test"
        x <- x - mu
        ZEROES <- any(x == 0)
        if (ZEROES) 
            x <- x[x != 0]
        n <- as.double(length(x))
        if (is.null(exact)) 
            exact <- (n < 50)
        r <- rank(abs(x))
        STATISTIC <- setNames(sum(r[x > 0]), "V")
        TIES <- length(r) != length(unique(r))
        if (exact && !TIES && !ZEROES) {
            PVAL <- switch(alternative, two.sided = {
                p <- if (STATISTIC > (n * (n + 1)/4)) psignrank(STATISTIC - 
                  1, n, lower.tail = FALSE) else psignrank(STATISTIC, 
                  n)
                min(2 * p, 1)
            }, greater = psignrank(STATISTIC - 1, n, lower.tail = FALSE), 
                less = psignrank(STATISTIC, n))
            if (conf.int) {
                x <- x + mu
                alpha <- 1 - conf.level
                diffs <- outer(x, x, "+")
                diffs <- sort(diffs[!lower.tri(diffs)])/2
                cint <- switch(alternative, two.sided = {
                  qu <- qsignrank(alpha/2, n)
                  if (qu == 0) qu <- 1
                  ql <- n * (n + 1)/2 - qu
                  achieved.alpha <- 2 * psignrank(trunc(qu) - 
                    1, n)
                  c(diffs[qu], diffs[ql + 1])
                }, greater = {
                  qu <- qsignrank(alpha, n)
                  if (qu == 0) qu <- 1
             
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值