## S3 method for class 'mnlm':
predict( object, newdata, type=c("response","reduction"), ... )
mnlm
function."response"
, an ncol(object$loadings)
-column matrix of new covariates.
Under "reduction"
, an nrow(object$loadings)
-column matrix of
multinomial phrase/category counts for new documtype="response"
, output is an nrow(newcounts)
by nrow(object$loadings)
matrix of
predicted probabilities for each response category.
Under type="reduction"
, output is an nrow(newcounts)
by ncol(object$loadings)
matrix of document
scores in each factor (object$covars
) direction.## fit a congress 109 mnlm model using a random 300 members
data(congress109)
train <- sample(1:529, 300)
counts <- congress109Counts[,col_sums(congress109Counts[train,])>0]
fitRep <- mnlm(counts[train,], congress109Ideology$repshare[train], normalize=TRUE, bins=10)
## extract the reduced dimension text score
Z <- predict(fitRep, newdata=counts[train,], type="reduction")
## use this to build a forward regression model
fwdRep <- lm(repshare ~ Z, data=data.frame(repshare=congress109Ideology$repshare[train], Z=Z[,1]) )
## predict scores for the out-of-sample members
Znew <- predict(fitRep, newdata=counts[-train,], type="reduction")
predicted <- predict(fwdRep, newdata=data.frame(Z=Znew[,1]))
plot(congress109Ideology$repshare[-train], predicted,
pch=21, bg=c(4,3,2)[congress109Ideology$party[-train]], xlab="repshare")
abline(a=0,b=1, col=8)
Run the code above in your browser using DataLab