6

I am trying to train a multinomial logit model and while I am at it I might as well make it a GAM and add splines to the mix.

I have tried using mgcv, but I have only managed to generate errors so far. Below are some examples using the iris dataset.

Do you have any idea how to make it converge?
thanks

library(tidyverse)
library(mgcv)
my_iris <- iris %>% 
  mutate(y =    as.integer(as.factor(Species)) -1) 
set.seed(8)

# this works (no spline)
mod1 <- gam(
  data = my_iris,
  formula = list(
    y ~ Sepal.Length + Petal.Length,
      ~ Sepal.Length + Petal.Length),
  family=multinom(K=2))

Model 2 (1 spline on petal width) crashes with the following warning :

Warning message:
 In newton(lsp = lsp, X = G$X, y = G$y, Eb = G$Eb, UrS = G$UrS, L = G$L,  :
Fitting terminated with step failure - check results carefully

.

mod2 <- gam(
  data = my_iris,
  formula = list(
    y ~ Sepal.Length + s(Petal.Width),
      ~ Sepal.Length + Petal.Length),
  family=multinom(K=2))

Model 3 (1 spline on petal length) crashes with the following warning :

Error in eigen(hess1, symmetric = TRUE) : 
infinite or missing values in 'x'

.

mod3 <- gam(
  data = my_iris,
  formula = list(
    y ~ Sepal.Length + s(Petal.Length),
      ~ Sepal.Length + Petal.Length),
  family=multinom(K=2))

Model 4 (2xsplines on Sepal.Length) crashes with the following warning :

Error in gam.fit5(x, y, sp, Sl = Sl, weights = weights, offset = offset,  : 
non finite values in Hessian

.

mod4 <- gam(
  data = my_iris,
  formula = list(
    y ~ s(Sepal.Length) + Petal.Length,
      ~ s(Sepal.Length) + Petal.Length),
  family=multinom(K=2))
Zoltan
  • 760
  • 4
  • 15

0 Answers0