У меня есть блестящее приложение, которое использует пакет mlogit, но созданные модели не работают, когда я меняю переменные - PullRequest
0 голосов
/ 10 ноября 2019

Я создал блестящее приложение, которое использует пакет mlogit,

в блестящем приложении, люди могут создавать собственные модели с различными переменными / атрибутами

Но когда я изменяю атрибуты вблестящее приложение, приложение вылетает

Это код:

Часть пользовательского интерфейса

   selectInput("B1V1","Variable 1:", c("All", unique(as.character(b1v1)))), 

Часть сервера

   b1v1 <- c(names(Quebec))
   x <- as.numeric(input$B1V1)

   hsmarketshare <- apply(predict(mlogit(choice ~ x, Quebec, reflevel = "gg"), Quebec, outcome=F),2,mean)


    output$modelcalcmarketshare <- renderTable(hsmarketshare)

Мое сообщение об ошибке

Warning in observeEventHandler(...) : NAs introduced by coercion
Warning: Error in model.frame.default: variable lengths differ (found for 'x')

Ответы [ 2 ]

0 голосов
/ 11 ноября 2019
    eventReactive(input$calcmodel,{

    setwd("/Users/trungioh/Desktop/R/Calc/Calc")

    library(tidyverse)
    library(mlogit)
    library(stargazer)

    quebec <- read.delim("quebec.dat")
    summary(quebec)


   quebec$cost_inc1 =NULL
   quebec$cost_inc2 =NULL
   quebec$cost_inc3 =NULL
   quebec$cost_inc4 =NULL
   quebec$cost_inc5 =NULL
   quebec$cost_inc6 =NULL
   quebec$cost_inc7 =NULL
   quebec$cost_inc8 =NULL
   quebec$cost_inc9 =NULL

   names(quebec)

   Quebec <- mlogit.data(quebec, 
                         shape="wide", 
                         choice="choice", 
                         varying=14:40,
                         sep="",
                         id="obs",

   alt.levels=c("gg","ge","deo","dee","oo","oe","ee","we","wee")
   )
   Quebec <- subset(Quebec, avail==1)
   names(Quebec)


   b1v1 <- c(names(Quebec))
   x <- as.numeric(input$B1V1)
   #y <- as.numeric(input$B1V2)
   #z <- as.numeric(input$B2V1)
   #a <- as.numeric(input$B2V2)
   #b <- input$REFLEVELVAR

   hsmarketshare <- apply(predict(mlogit(choice ~ x, Quebec, reflevel = "gg"), Quebec, outcome=F),2,mean)


    output$modelcalcmarketshare <- renderTable(hsmarketshare())
  })  
0 голосов
/ 11 ноября 2019
eventReactive(input$calcmodel,{

b1v1 <- c(names(Quebec))
x <- as.numeric(input$B1V1)

hsmarketshare <- apply(predict(mlogit(choice ~ x, Quebec, reflevel = "gg"), 
Quebec, outcome=F),2,mean)


output$modelcalcmarketshare <- renderTable(hsmarketshare())
})

Я перешел на эту функцию, но теперь ничего не происходит

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...