user2978524
user2978524

Reputation: 501

Error in Multinominal regression: "NAs are not allowed in subscripted assignments"

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.

Upvotes: 1

Views: 2355

Answers (1)

MrFlick
MrFlick

Reputation: 206197

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.

Upvotes: 2

Related Questions