2017-03-07 4 views
0

質問は次のように与えられます:バイナリt-統計量を表現する方法は?

ファイルdiabetes.csvを読んでください。 BMIとアウトカムという2つの変数があります。 0とBMIの標準偏差は、両方の結果について同じである1行動仮説のためのノンパラメトリック2つのサンプル試験データは、いくつかのデータセットである

bmi <- diabetes$BMI 
bmi 
outcome <- diabetes$Outcome 
outcome 

n <- length(bmi) 

# tstat 
tstat <- ??? 

# Describe the population and draw synthetic samples 
f1 <- function() 
{ 
    x <- c(bmi, outcome) 
    x <- sample(x) 
    m1 <- sd(x[1:n]) 
    m2 <- sd(x[(n+1):length(x)]) 
    return(m1 - m2) 
} 

# Create sampling distribution 
sdist <- replicate(10000, f1()) 
plot(density(sdist)) 

# Gap 
gap <- abs(mean(sdist) - tstat) 
abline(v = mean(sdist) + c(-1,1) * gap, col = "dark orange") 
s1 <- sdist[sdist <(mean(sdist - gap)) | sdist >(mean(sdist + gap))] 
pvalue <- length(s1)/length(sdist) 
pvalue 

値:変数成果は、2つのだけの値が上で取ります「糖尿病」と呼ばれる。私の質問は、結果がバイナリであるため、 "t-統計"をどのように表現するかです。

答えて

0

使用このコード:

# Sort the table diabetes on accending order of Outcome to separate the BMI 
# values with outcome = 0 and BMI values with outcome = 1 

diabetes = diabetes[order(diabetes$Outcome),] 
View(diabetes) 

# Find the number of values with outcome = 0 

n = length(which(diabetes$Outcome == 0)) 

# Find total number of rows 

l = length(diabetes$BMI)    

# Find BMI values to create the sample later on 

g = diabetes$BMI       

# Create function to take the values of BMI and shuffle it every time and 
# to find the difference between the standard deviations 

f1 = function() 
{ 
    x = sample(g)    
    z = abs(sd(x[1:n]) - sd(x[(n+1):l])) 
    return(z) 
} 

# Replicate the function several times 

dist = replicate(100000,f1())   

# Plot density of distribution 

plot(density(dist))      

polygon(density(dist),col="green") 


diabetes0 = diabetes[diabetes$Outcome == 0,] 
diabetes1 = diabetes[diabetes$Outcome == 1,] 

View(diabetes0) 
View(diabetes1) 

# Find the difference between standard deviation of BMI when outcome = 0 and 
# when outcome = 1 

tstat = abs(sd(diabetes0$BMI) - sd(diabetes1$BMI))  

tstat 

abline(v=tstat)           
rside = dist[dist>tstat]  


pvalue = length(rside)/length(dist) 
pvalue 
関連する問題