title: Error: $ operator not defined for this S4 class while running hoslem.test
body: <p>I'm working on an optimization of a logistic regression model made with <code>glm</code>, the optimization is a lasso regression using <code>glmnet</code>. I want to compare both models using the output of a Hosmer Lemeshow test and I get this output.
  For the <code>glm</code> I get</p>
  
  <pre><code>&gt; hl &lt;- hoslem.test(trainingDatos$Exited, fitted(logit.Mod))
  &gt; hl
  
      Hosmer and Lemeshow goodness of fit (GOF) test
  
  data:  trainingDatos$Exited, fitted(logit.Mod)
  X-squared = 2.9161, df = 8, p-value = 0.9395
  </code></pre>
  
  <p>And when I try to run the test for the lasso regression I get </p>
  
  <pre><code>&gt; hll &lt;- hoslem.test(trainingDatos$Exited, fitted(lasso.model), g=10)
  Error in cut.default(yhat, breaks = qq, include.lowest = TRUE) : 
    'x' must be numeric
  </code></pre>
  
  <p>I also tried to use the coefficients of the lasso regression to make it numeric and I get</p>
  
  <pre><code>&gt; hll &lt;- hoslem.test(trainingDatos$Exited, fitted(lasso.model$beta), g=10)
  Error: $ operator not defined for this S4 class
  </code></pre>
  
  <p>But when I treat it as an S4</p>
  
  <pre><code>&gt; hll &lt;- hoslem.test(trainingDatos$Exited, fitted(lasso.model@beta), g=10)
  Error in fitted(lasso.model@beta) : 
    trying to get slot "beta" from an object (class "lognet") that is not an S4 object
  </code></pre>
  
  <p>Any way to run the test for my lasso regression?
  Here is my full code for the lasso regression, can't share the database right now sorry</p>
  
  <pre><code>    #Creation of Training Data Set
  input_ones &lt;- Datos[which(Datos$Exited == 1), ] #All 1s
  input_zeros &lt;- Datos[which(Datos$Exited == 0), ] #All 0s
  set.seed(100) 
  #Training 1s
  input_ones_training_rows &lt;- sample(1:nrow(input_ones), 0.7*nrow(input_ones)) 
  #Training 0s
  input_zeros_training_rows &lt;- sample(1:nrow(input_zeros), 0.7*nrow(input_ones)) 
  training_ones &lt;- input_ones[input_ones_training_rows, ]
  training_zeros &lt;- input_zeros[input_zeros_training_rows, ]
  trainingDatos &lt;- rbind(training_ones, training_zeros) 
  library(glmnet)
  #Conversion of training data into matrix form
  x &lt;- model.matrix(Exited ~ CreditScore + Geography + Gender
                    + Age + Tenure + Balance + IsActiveMember
                    + EstimatedSalary, trainingDatos)[,-1]
  #Defining numeric response variable
  y &lt;- trainingDatos$Exited
  sed.seed(100) 
  #Grid search to find best lambda
  cv.lasso&lt;-cv.glmnet(x, y, alpha = 1, family = "binomial")
  #Creation of the model
  lasso.model &lt;- glmnet(x, y, alpha = 1, family = "binomial", 
                        lambda = cv.lasso$lambda.1se)
  coef(cv.lasso, cv.lasso$lambda.1se)
  #Now trying to run the test
  library(ResourceSelection)
  set.seed(12657)
  hll &lt;- hoslem.test(trainingDatos$Exited, fitted(lasso.model), g=10)#numeric value error
  hll &lt;- hoslem.test(trainingDatos$Exited, fitted(lasso.model$beta), g=10)#$ not defined for S4
  hll &lt;- hoslem.test(trainingDatos$Exited, fitted(lasso.model@beta), g=10)#saying that beta is nos S4
  </code></pre>