2016-06-17 64 views
-1

我對閃亮相當新穎,而且我知道y的問題相當簡單,但儘管做了大量的研究,但我似乎無法使閃亮渲染輸出比例功率的測試。我試圖在用戶輸入所有參數(p1,p2,sig.level,power)的情況下創建腳本,並給出樣本大小n。我嘗試了許多不同的方法,但通常最終沒有輸出,或者錯誤「n」,「p1」,「p2」,「power」和「sig.level」中的某一個必須爲NULL「 。任何幫助表示讚賞,謝謝!針對樣本尺寸的power.prop.test函數的閃亮渲染輸出

到目前爲止我的代碼:

ui<-shinyUI(fluidPage(
    headerPanel("Power Calculator"), 
    fluidRow(
    column(12, 
     wellPanel(
     helpText("This calculator can help you understand the power of 
        your experimental design to detect treatment effects. You  
     can choose 
        between a standard design in which individuals are randomly 
     assigned to treatment or control 
        and a clustered design, in which groups of individuals are assigned to treatment 
        and control together."), 
     column(4, 
       wellPanel(

     numericInput('p1a','prop1', value = 0.12, min = 0.01, max = 0.99), 
     numericInput('p2a', 'prop2', value = 0.14, min = 0.01, max = 0.99), 
     numericInput('sig.levela','significance level' , value = 0.95, min = 0.9, max = 0.99), 
     numericInput('powera', 'power level', value = 0.8, min = 0.75, max = 0.99) 
       ), 
     column(8, 
       wellPanel(
        htmlOutput("nrequired") 

       ) 
     ) 
     ) 
     ) 
     ) 
     ) 
     ) 
     ) 
     ) 

     server<-shinyServer(
     function(input, output) { 



     sample.size<-reactive({ 
    p1<-input$p1a 
    p2<-input$p2a 
    sig.level<-input$sig.level$a 
    power<-input$power.levela 

}) 


output$nrequired <- renderPrint({ 
power.prop.test(sample.size) 
print(sample.size) 
}) 

} 
) 

shinyApp(ui=ui,server=server) 
+0

請不要大寫R函數的名稱,當它們沒有實際上限制時。它混淆了其他新手。 (錯誤信息似乎很合理清楚,你提供了一個參數,並預期有四個函數。) –

+0

對不起,你指的是什麼capitilization?我還補充說,當我提供所有參數(p1,p2,sig.level和power)時,我得到這個錯誤 –

+0

「Power.Prop.Test函數」 –

回答

1

錯誤消息來自哪個power.prop.test通過使反應性表達sample.size作爲參數傳遞給它引起的。

請嘗試如下修改服務器功能:

server <- shinyServer(function(input, output) { 
    output$nrequired <- renderPrint({ 
    power.prop.test(p1 = input$p1a, p2 = input$p2a, 
        sig.level = input$sig.levela, power = input$powera) 
    }) 
}) 

BTW:我想知道你所選擇的0.95 sig.level參數的同時power.prop.test使用的0.05的默認值。

+0

謝謝你清理那個! –

+0

我很高興你能感謝我的回答。請介意點擊左側的複選標記接受我的回答嗎?謝謝。 – Uwe