我模擬了隨機數據集與給定的特徵和一切工作只是罰款:
df <- data.frame(Subject = c("Sub1", "Sub2", "Sub3", "Sub4", "Sub5", "Sub6", "Sub7", "Sub8", "Sub9", "Sub10", "Sub11", "Sub12", "Sub13", "Sub14", "Sub15", "Sub16", "Sub17", "Sub18", "Sub19", "Sub20", "Sub21", "Sub22", "Sub23", "Sub24", "Sub25", "Sub26", "Sub27", "Sub28", "Sub29", "Sub30"),
Disability = c("0", "0", "1", "1", "1", "1", "0", "0", "0", "1", "1", "0", "0", "0", "0", "1", "0", "0", "1", "0", "0", "0", "0", "1", "1", "1", "0", "0", "1", "0"),
Pref = c("touchpad", "touchpad", "touchpad", "trackball", "trackball", "trackball", "trackball", "trackball", "trackball", "trackball", "trackball", "trackball", "touchpad", "trackball", "trackball", "touchpad", "touchpad", "trackball", "touchpad", "trackball", "touchpad", "touchpad", "trackball", "touchpad", "touchpad", "touchpad", "touchpad", "touchpad", "trackball", "trackball"))
給定的命令的結果是以下
binom.test(sum(df[df$Disability == "0",]$Pref == "touchpad"),
nrow(df[df$Disability == "0",]), p=1/2)
Exact binomial test
data: sum(df[df$Disability == "0", ]$Pref == "touchpad") and nrow(df[df$Disability == "0", ])
number of successes = 8, number of trials = 18, p-value = 0.8145
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.2153015 0.6924283
sample estimates:
probability of success
0.4444444
編輯
爲了將相同的測試應用於真實數據(鏈接到評論中給出的文件),第一步應當由命令讀出存儲在實際數據幀中的值來替換:
df <- read.csv("deviceprefs-1.csv")
另外,給出的命令執行二項式檢驗工作得很好與真實數據組。
如果您提供了您正在使用的數據,那會更好,因此我們可以重現您的代碼。試試'dput',或者在某處上傳這個csv併發佈一個鏈接。 –
也請在問題中添加錯誤消息。 –
感謝您的幫助!我只是想出了我需要用構建的xtab的名稱替換「df」。文件:https://www.dropbox.com/s/rd796wor7by5uky/DesignExperiments_R.Rproj?dl=0 https://www.dropbox.com/s/cig2u4d5vpkjma1/deviceprefs.csv?dl = 0 – testimo