Does the function multinom() from R's nnet package fit a multinomial logistic regression, or a Poisson regression? - r

The documentation for the multinom() function from the nnet package in R says that it "[f]its multinomial log-linear models via neural networks" and that "[t]he response should be a factor or a matrix with K columns, which will be interpreted as counts for each of K classes." Even when I go to add a tag for nnet on this question, the description says that it is software for fitting "multinomial log-linear models."
Granting that statistics has wildly inconsistent jargon that is rarely operationally defined by whoever is using it, the documentation for the function even mentions having a count response and so seems to indicate that this function is designed to model count data. Yet virtually every resource I've seen treats it exclusively as if it were fitting a multinomial logistic regression. In short, everyone interprets the results in terms of logged odds relative to the reference (as in logistic regression), not in terms of logged expected count (as in what is typically referred to as a log-linear model).
Can someone clarify what this function is actually doing and what the fitted coefficients actually mean?

nnet::multinom is fitting a multinomial logistic regression as I understand...
If you check the source code of the package, https://github.com/cran/nnet/blob/master/R/multinom.R and https://github.com/cran/nnet/blob/master/R/nnet.R, you will see that the multinom function is indeed using counts (which is a common thing to use as input for a multinomial regression model, see also the MGLM or mclogit package e.g.), and that it is fitting the multinomial regression model using a softmax transform to go from predictions on the additive log-ratio scale to predicted probabilities. The softmax transform is indeed the inverse link scale of a multinomial regression model. The way the multinom model predictions are obtained, cf.predictions from nnet::multinom, is also exactly as you would expect for a multinomial regression model (using an additive log-ratio scale parameterization, i.e. using one outcome category as a baseline).
That is, the coefficients predict the logged odds relative to the reference baseline category (i.e. it is doing a logistic regression), not the logged expected counts (like a log-linear model).
This is shown by the fact that model predictions are calculated as
fit <- nnet::multinom(...)
X <- model.matrix(fit) # covariate matrix / design matrix
betahat <- t(rbind(0, coef(fit))) # model coefficients, with expicit zero row added for reference category & transposed
preds <- mclustAddons::softmax(X %*% betahat)
Furthermore, I verified that the vcov matrix returned by nnet::multinom matches that when I use the formula for the vcov matrix of a multinomial regression model, Faster way to calculate the Hessian / Fisher Information Matrix of a nnet::multinom multinomial regression in R using Rcpp & Kronecker products.
Is it not the case that a multinomial regression model can always be reformulated as a Poisson loglinear model (i.e. as a Poisson GLM) using the Poisson trick (glmnet e.g. uses the Poisson trick to fit multinomial regression models as a Poisson GLM)?

Related

comparison of goodness-of-fit under robust circumstances [migrated]

This question was migrated from Stack Overflow because it can be answered on Cross Validated.
Migrated yesterday.
I have fitted respectively a zero-knot, a one-knot and a two-knot linear spline to my data, and I need some index of goodness-of-fit for model selection. The crucial point is that the splines are fitted with robust linear regressions (using function rlm in R package MASS), specifically with Huber estimations and Tukey's bisquare estimation, which makes the usual estimator of prediction error like AIC inappropriate.
So my problem is:
What criterion should I use to perform model selection on my zero, one and two-knot splines? Can I use SSE?
I also need to compare between a model using Huber estimation and a model using Tukey's bisquare estimation. What criterion should I use?

Ordinal logistic regression (or Beta regression) with a LASSO regularization in R?

I was wondering if someone would know an R package that would allow me to fit an Ordinal Logistic regression with a LASSO regularization or, alternatively, a Beta regression still with the LASSO? And if you also know of a nice tutorial to help me code that in R (with appropriate cross-validation), that would be even better!
Some context: My response variable is a satisfaction score between 0 and 10 (actually, values lie between 2 and 10) so I can model it with a Beta regression or I can convert its values into ranked categories. My interest is to identify important variables explaining this score but as I have too many potential explanatory variables (p = 12) compared to my sample size (n = 105), I need to use a penalized regression method for model selection, hence my interest in the LASSO.
The ordinalNet package does this. There's a paper with example here:
https://www.jstatsoft.org/article/download/v099i06/1440
Also the glmnetcr package: https://cran.r-project.org/web/packages/glmnetcr/vignettes/glmnetcr.pdf

R code to get Log-likelihood for Binary logistic regression

I have developed a binomial logistic regression using glm function in R. I need three outputs which are
Log likelihood (no coefficients)
Log likelihood (constants only)
Log likelihood (at optimal)
What functions or packages do I need to obtain these outputs?
Say we have a fitted model m.
log-likelihood of full model (i.e., at MLE): logLik(m)
log-likelihood of intercept-only model: logLik(update(m, . ~ 1))
although the latter can probably be retrieved without refitting the model if we think carefully enough about the deviance() and $null.deviance components (these are defined with respect to the saturated model)

R Packages for own penalized Regression Matrix

I want to do a multivariate regression. I have y, which is a matrix, and one vector x, which is my predictor variable. I want to do a multivariate regression while penalizing the coefficients I get. Something like:
$||y-xb|| + \lambda b^t P b $
But I have a "own" penalty term which I want to use for penalized regression. When I searched for penalized regression, I found a lot of packages but all of them have predefined penalties like lasso, ridge or second differences.
I used the gam() package in mgcv when I had a univariate response:
gam(Y~x_1, paraPen = penaltymatrix)
but this package do not support multivariate regression.
Is there any R package where I can use an individual penalty matrix with my coefficients? Or can you give me any advice on how to solve the problem I have?

Can I test autocorrelation from the generalized least squares model?

I am trying to use a generalized least square model (gls in R) on my panel data to deal with autocorrelation problem.
I do not want to have any lags for any variables.
I am trying to use Durbin-Watson test (dwtest in R) to check the autocorrelation problem from my generalized least square model (gls).
However, I find that the dwtest is not applicable over gls function while it is applicable to other functions such as lm.
Is there a way to check the autocorrelation problem from my gls model?
Durbin-Watson test is designed to check for presence of autocorrelation in standard least-squares models (such as one fitted by lm). If autocorrelation is detected, one can then capture it explicitly in the model using, for example, generalized least squares (gls in R). My understanding is that Durbin-Watson is not appropriate to then test for "goodness of fit" in the resulting models, as gls residuals may no longer follow the same distribution as residuals from the standard lm model. (Somebody with deeper knowledge of statistics should correct me, if I'm wrong).
With that said, function durbinWatsonTest from the car package will accept arbitrary residuals and return the associated test statistic. You can therefore do something like this:
v <- gls( ... )$residuals
attr(v,"std") <- NULL # get rid of the additional attribute
car::durbinWatsonTest( v )
Note that durbinWatsonTest will compute p-values only for lm models (likely due to the considerations described above), but you can estimate them empirically by permuting your data / residuals.

Resources