Learn R Programming

textir (version 1.8-5)

predict.mnlm: mnlm predict

Description

Predict function for Multinomial Logistic Regression

Usage

## S3 method for class 'mnlm':
predict( object, newdata, type=c("response","reduction"), ... )

Arguments

object
An output object from the mnlm function.
type
Under "reduction", provide the fitted reduction $F\phi$. Under "response", provide the fitted multinomial probabilities.
newdata
Under "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 docum
...
Additional unused arguments.

Value

  • Under type="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.

Details

Under 'response', this returns fitted multinomial probabilities given new covariate vectors. Under 'reduction', we provide the sufficient reduction $F\Phi$ for new documents, with $F$ a document-term frequency matrix (i.e., the counts divided by document totals).

References

Taddy (2011), Inverse Regression for Analysis of Sentiment in Text. http://arxiv.org/abs/1012.2098

See Also

mnlm, congress109

Examples

Run this code
## 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