r - Multinom with Matrix of Counts as Response -


according of multinom, package nnet, "the response should factor or matrix k columns, interpreted counts each of k classes." tried use function in second case, obtaining error.

here sample code of do:

response  <- matrix(round(runif(200,0,1)*100),ncol=20) # 10x20 matrix of counts predictor <- runif(10,0,1) fit1 <- multinom(response ~ predictor) weights1 <- predict(fit1, newdata = 0.5, "probs") 

here obtain:

'newdata' had 1 row variables found have 10 rows 

how can solve problem?

bonus question: noticed can use multinom predictor of factors, e.g. predictor <- factor(c(1,2,2,3,1,2,3,3,1,2)). cannot understand how mathematically possible, given multinomial linear logit regression should work continuous or dichotomous predictors.

the easiest method obtaining predictions new variable define new data data.frame.

using sample code

> predict(fit1, newdata = data.frame(predictor = 0.5), type = "probs")  [1] 0.07231972 0.05604055 0.05932186 0.07318140 0.03980245 0.06785690 0.03951593 0.02663618  [9] 0.04490844 0.04683919 0.02298260 0.04801870 0.05559221 0.04209283 0.03799946 0.06406533 [17] 0.04509723 0.02197840 0.06686314 0.06888748 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -