2016-08-23 4 views
1

나는 비율의 차이를 비교하기 위해 marascuilio 절차를 진행하고 있습니다. 나는 다음과 같은 this tutorial에서 복사 및 적응 코드 (사용하고 있습니다. 내가 출력도 종류가 정확히 비교되는 예를 들어 어떤 범주의 레이블을()에서 인쇄 할 필요가Marascuilo procedure in R

## Set the proportions of interest. 
p = c(0.3481, 0.1730, 0.4788) 
N = length(p) 
value = critical.range = c() 

## Compute critical values. 
for (i in 1:(N-1)) 
{ for (j in (i+1):N) 
{ 
    value = c(value,(abs(p[i]-p[j]))) 
    critical.range = c(critical.range, 
        sqrt(qchisq(.95,3))*sqrt(p[i]*(1-p[i])/12000 + p[j]*(1-p[j])/12000)) 
} 
} 
round(cbind(value,critical.range),3) 

을 그래서

범주가 구분 벡터에 나와있는 경우, 예를 들어 categories <- c("cat1", "cat2", cat"3)는 비교가 cat1-cat2, cat1-cat3cat2-cat3이다. 난 내 출력이 라벨을 추가 할 수있는 방법

?

,691,363 (210)
value critical.range 
[1,] 0.175   0.016 
[2,] 0.131   0.018 
[3,] 0.306   0.016 
+0

어떻게해야 위의 예처럼 출력 dataframe 모양? – thepule

+0

예제를 추가 했으므로 기본적으로 다른 열을 추가하고 범주 비교에 대한 정보를 전달해야합니다. –

답변

1

이 시도 :

## Set the proportions of interest. 
p = c(0.3481, 0.1730, 0.4788) 
N = length(p) 
value = critical.range = tag = c() 
categories <- c("cat1", "cat2", "cat3") 

## Compute critical values. 
for (i in 1:(N-1)){ 
    for (j in (i+1):N){ 

    value <- c(value,(abs(p[i]-p[j]))) 
    critical.range = c(critical.range, 
         sqrt(qchisq(.95,N-1))*sqrt(p[i]*(1-p[i])/12000 + p[j]*(1-p[j])/12000)) 
    tag = c(tag, paste(categories[i], categories[j], sep = "-")) 

    } 
} 
df <- as.data.frame(cbind(value,critical.range, tag), stringsAsFactors = F) 
df$value <- round(as.numeric(df$value),3) 
df$critical.range <- round(as.numeric(df$critical.range),3) 

출력 :

value critical.range  tag 
1 0.175   0.016 cat1-cat2 
2 0.131   0.018 cat1-cat3 
3 0.306   0.016 cat2-cat3 
+1

중대합니다. 'df $ significance <- ifelse (df $ value> df $ critical.range, "yes", "no") '을'df'에 추가하므로 비교가 중요한지 여부를 나타냅니다. –