Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Is there a way to get `cor` to work?

未关闭
#90 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
r
领域
data

调研方向

首先重现报告的 cor(DelayedArray(x), DelayedArray(y)) 错误,并将其与提供的 delayedCov 示例进行比较。以 issue 中描述的 Pearson 相关行为为目标,并验证等效的矩阵和 DelayedArray 输入在没有数值类型错误的情况下产生匹配的结果。

由索引模型根据 Issue 内容生成。

描述

When I try cor, I get errors like Error in cor(DelayedArray(x), DelayedArray(y)) : 'x' must be numeric. Am I missing something simple?

If it's not implemented, I have a little function for this and I could send a pull request.

#' Drop-in replacement for cov or cor; tolerates DelayedArray input. Pearson correlation only. 
#'
delayedCov = function(x, y = x, do_cor = F){
  mux = colMeans(x)
  muy = colMeans(y)
  zx = sweep(x, 2, mux, "-")
  zy = sweep(y, 2, muy, "-")
  covxy = t(zx) %*% zy
  covxy = covxy / nrow(x)
  if(do_cor){
    sx = sqrt(colMeans(zx^2))
    sy = sqrt(colMeans(zy^2))
    covxy = Matrix::Diagonal(x = 1/sx) %*% covxy %*% Matrix::Diagonal(x = 1/sy)
  }
  covxy
}
# tests
x = matrix(rnorm(1000), ncol = 10)
y = matrix(rnorm(1000), ncol = 10)
plot(delayedCov(x, y),  cov(x, y)); abline(a = 0, b = 1)
plot(delayedCov(x, y, do_cor = T),  cor(x, y)); abline(a = 0, b = 1)
plot(delayedCov(DelayedArray(x), DelayedArray(y), do_cor = T),  cor(x, y)); abline(a = 0, b = 1)

主要语言
R
星标
29
派生
12
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Bioconductor/DelayedArray 的其他 Issue

查看 Bioconductor/DelayedArray 的全部 Issue

相似的 Issue

更多 R Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。