我正在读取一个csv文件,该文件由两个来源的两列数据组成。我想找到它们之间的p值,但是,我得到了标题中提到的错误。
library(psych)
RfileX = read.csv(fpath, header = TRUE)
x = as.matrix(RfileX)
a=x[1:52,1]
b=x[1:52,2]
print(corr.test(a,b, adjust = "none"), short = FALSE)
参考数据(Ls是什么意思?,谢谢)
structure(list(A1 = c(2L, 2L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 3L),
B1 = c(3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 2L)), .Names = c("A1",
"B1"), row.names = c(NA, 10L), class = "data.frame")
答案 0 :(得分:2)
假设psych
包。
如果您阅读?corr.test
,您会看到前两个参数是:
x: A matrix or dataframe
y: A second matrix or dataframe with the same number of rows as
x
不向量。所以,你应该能够运行corr.test(RfileX, ...)
,ala:
library(psych)
set.seed(42)
x <- data.frame(a = sample(2:3, size = 100, replace = TRUE),
b = sample(2:3, size = 100, replace = TRUE))
print(corr.test(x, adjust = "none"), short = FALSE)
# Call:corr.test(x = x, adjust = "none")
# Correlation matrix
# a b
# a 1.00 0.13
# b 0.13 1.00
# Sample Size
# [1] 100
# Probability values (Entries above the diagonal are adjusted for multiple tests.)
# a b
# a 0.0 0.2
# b 0.2 0.0
# To see confidence intervals of the correlations, print with the short=FALSE option
# Confidence intervals based upon normal theory. To get bootstrapped values, try cor.ci
# lower r upper p
# a-b -0.07 0.13 0.32 0.2