2016-12-29 3 views
-1

두 소스의 두 데이터 열로 구성된 csv 파일을 읽었습니다. 두 값 사이의 p 값을 찾고 싶습니다. 그러나 나는 제목에 언급 된 오류를 얻는다. 참조오류 : 상관 분석을 시도 할 때 "1 : ncol (y) : 길이가 0 인 인수 오류"

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") 
+2

데이터 이미지를 첨부하지 마십시오. 'dput (head (RfileX, n = 10)) '을 타이프하고 여기의 코드 블록에 붙여 넣는 것도 쉽습니다. – r2evans

+0

Btw., 길이가 다른 두 벡터의 상관 관계를 계산할 수 없습니다. – Roland

+0

죄송합니다. 오타였습니다. 벡터의 길이는 같습니다. – Vinkebot

답변

2

psych 패키지를 가정.

x: A matrix or dataframe 

    y: A second matrix or dataframe with the same number of rows as 
     x 

하지 벡터 :

당신이 ?corr.test을 읽는다면

, 당신은 처음 두 개의 인수가 있음을 볼 수 있습니다. 따라서 다음을 실행하여 corr.test(RfileX, ...)을 (를) 실행할 수 있어야합니다.

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 
관련 문제