1

I'm doing Multinominal regression with the help of this site.

I got error while doing:

    > dses1 <- data.frame(ses = c("Cluster1", "Cluster2", "Cluster3"), GDP = mean(data.mod$GDP.z))
    > dses1
           ses         GDP
    1 Cluster1 -0.03853141
    2 Cluster2 -0.03853141
    3 Cluster3 -0.03853141

    > predict(results, newdata = dses1, "probs")  
    NAs are not allowed in subscripted assignments

I've done regression as follows

    results <- multinom(data.mod$baseline~data.mod$cluster+data.mod$GDP.z+data.mod$WGI.z,data=data.mod)

Dataset is like this:

    > head(data.mod)
       cluster  type       GDP.z     WGI.z baseline
    1 Cluster3 Type1 -0.15927872 0.0750328    Type1
    2 Cluster3 Type1  0.18363900 0.1066325    Type1
    3 Cluster1 Type1  1.58636819 0.0750328    Type1
    4 Cluster3 Type1 -0.27892696 0.7034406    Type1
    5 Cluster3 Type1 -0.37910360 0.6864063    Type1
    6 Cluster2 Type1 -0.09978649 0.0750328    Type1

I already checked this stack, but got the same error again.

Community
  • 1
  • 1
user2978524
  • 471
  • 1
  • 3
  • 15

1 Answers1

2

When you use predict, it needs to match up column names exactly with those shown by coef(results). Since you unnecessarily left the table name prefix on all your variable names, that's probably what's causing the error. Try

results <- multinom(baseline~cluster + GDP.z + WGI.z, data=data.mod)

Also you seem to be missing WGI.z form your newdata (Since it was in the model, it has to be there). So your newdata should be

dses1 <- data.frame(cluster = c("Cluster1", "Cluster2", "Cluster3"), 
    GDP.z = mean(data.mod$GDP.z),
    WGI.z = mean(data.mod$WGI.z)
)

and those names should match the names in your formula so you should be all set.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • @user2978524 If it works, please consider clicking the checkmark by this answer to accept it. That's how StackOverflow works. – MrFlick May 24 '14 at 16:00
  • All right. Thanks. I wonder if you know a good way to visualize the results. The [webpage](http://www.ats.ucla.edu/stat/r/dae/mlogit.htm) can't use for my case, since there are two control variables:GDP and WGI. – user2978524 May 24 '14 at 18:36
  • @user2978524 Comments are not a good place to ask new questions. feel free to start a new post if you have a different question. Although, broad, opinion-based questions like "how do i visualize this data" are frowned upon on this site. It should be a specific programming question. – MrFlick May 24 '14 at 20:14