# predict.npmr: Make predictions from a "npmr" object In npmr: Nuclear Penalized Multinomial Regression

## Description

Return predicted reponse class probabilities from a fitted NPMR model, for each value of lambda on which the NPMR model was originally fit.

## Usage

 ```1 2``` ```## S3 method for class 'npmr' predict(object, newx, ...) ```

## Arguments

 `object` an object of class `npmr` `newx` covariate matrix on which for which to make response class probability predictions. Must have same number of columns as `X` used original to fit `object`. `...` ignored

## Value

a 3-dimensional array, with dimensions (`nrow(newx), ncol(Y), length(lambda)`). For each lambda, this array stores for that value of lambda the predicted response class probabilites for each observation.

## Author(s)

Scott Powers, Trevor Hastie, Rob Tibshirani

## References

Scott Powers, Trevor Hastie and Rob Tibshirani (2016). “Nuclear penalized multinomial regression with an application to predicting at bat outcomes in baseball.” In prep.

`npmr`, `predict.cv.npmr`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32``` ```# Fit NPMR to simulated data K = 5 n = 1000 m = 10000 p = 10 r = 2 # Simulated training data set.seed(8369) A = matrix(rnorm(p*r), p, r) C = matrix(rnorm(K*r), K, r) B = tcrossprod(A, C) # low-rank coefficient matrix X = matrix(rnorm(n*p), n, p) # covariate matrix with iid Gaussian entries eta = X P = exp(eta)/rowSums(exp(eta)) Y = t(apply(P, 1, rmultinom, n = 1, size = 1)) # Simulate test data Xtest = matrix(rnorm(m*p), m, p) etatest = Xtest Ptest = exp(etatest)/rowSums(exp(etatest)) Ytest = t(apply(Ptest, 1, rmultinom, n = 1, size = 1)) # Fit NPMR for a sequence of lambda values without CV: fit2 = npmr(X, Y, lambda = exp(seq(7, -2))) # Compute mean test error using the predict function (for each value of lambda): getloss = function(pred, Y) { -mean(log(rowSums(Y*pred))) } apply(predict(fit2, Xtest), 3, getloss, Ytest) ```