gpt4 book ai didi

c - acf 函数的 R 源文件

转载 作者:行者123 更新时间:2023-12-04 11:38:02 25 4
gpt4 key购买 nike

acf R 的 stats 库中的函数包括该行

.Call(C_acf, x, lag.max, type == "correlation")

但我找不到文件 C_acf我机器上的任何地方(也不在 https://github.com/SurajGupta/r-source 也不在 https://github.com/wch/r-source )。

在这些问题上应用建议并没有帮助:

https://stats.stackexchange.com/questions/254227/manual-calculation-of-acf-of-a-time-series-in-r-close-but-not-quite

How to see the source code of R .Internal or .Primitive function?

该文件似乎不在人们说要查看的任何地方。我怎样才能找到 C_acf?

最佳答案

此方法将有助于识别类为 CallRoutine 的已编译函数的源代码。或 NativeSymbolInfo .

查找调用例程的命名空间

getAnywhere(C_acf)
# namespace:stats

下载您的基础 R 版本,因为 stats 是基础 R 的一部分。
download.file(url = "https://cran.r-project.org/src/base/R-3/R-3.0.0.tar.gz", destfile = "./R-3.0.0.tar.gz")
untar(tarfile = "./R-3.0.0.tar.gz", exdir = "./")

处理目录路径
old_dir <- getwd()
setwd("./R-3.0.0/src/library/stats/src/")

找到这个词 acf在源文件中。您必须查看结果列表并确定确切的函数。最简单的方法是查看函数名称及其参数。
myresults <- sapply( list.files("./"), function(x) grep("acf", readLines(x), value = TRUE))
myresults <- myresults[lengths(myresults) != 0]
myresults[2]
# $filter.c
# [1] "acf0(double *x, int n, int ns, int nl, int correlation, double *acf)"
# [2] "\t\tacf[lag + d1*u + d2*v] = (nu > 0) ? sum/(nu + lag) : NA_REAL;"
# [3] "\t se[u] = sqrt(acf[0 + d1*u + d2*u]);"
# [4] "\t\tacf[0 + d1*u + d2*u] = 1.0;"
# [5] "\t\t\tacf[lag + d1*u + d2*v] /= se[u]*se[v];"
# [6] "SEXP acf(SEXP x, SEXP lmax, SEXP sCor)"
# [7] " acf0(REAL(x), nx, ns, lagmax, cor, REAL(ans));"

重置旧目录路径
setwd(old_dir)

引用:
  • 1
  • 2
  • 关于c - acf 函数的 R 源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48673423/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com