1

I'm trying to test heteroskedasticity in different models namely in linear regreesion model, polynomial regression model, and generalized additive model. Using the ols_test_breusch_pagan function library(olsrr) I can test heteroskedasticity for linear and polynomial models but I couldn't figure out how to test heteroskedasticity in the generalized additive model (GAM). I followed the below process to test heteroskedasticity in the linear and polynomial models.

    ##################
    ###Linear Model###
    ##################
    >sm1 <- lm(adN ~ GC3 , data = train.data)
    >ols_test_breusch_pagan(sm1)
    ###########################################
     Breusch Pagan Test for Heteroskedasticity
     -----------------------------------------
     Ho: the variance is constant            
     Ha: the variance is not constant        
    
                 Data               
     -------------------------------
     Response : adN 
     Variables: fitted values of adN 
    
            Test Summary          
     -----------------------------
     DF            =    1 
     Chi2          =    0.04513367 
     Prob > Chi2   =    0.8317584

     ######################
     ###Polynomial Model###
     ######################
    >poly_degree(train.data$GC3, train.data$adN, type = "BIC")
    5
    >pm1 <- lm(adN ~ poly(GC3, 5, raw = TRUE), data = train.data)
    >ols_test_breusch_pagan(pm1)
    
     Breusch Pagan Test for Heteroskedasticity
     -----------------------------------------
     Ho: the variance is constant            
     Ha: the variance is not constant        
    
                 Data               
     -------------------------------
     Response : adN 
     Variables: fitted values of adN 
    
            Test Summary          
     -----------------------------
     DF            =    1 
     Chi2          =    0.02017309 
     Prob > Chi2   =    0.8870547 

Therefore, It suggests that the polynomial model is better for addressing heteroskedasticity in the data. Now I want to know how can I test heteroskedasticity in the generalized additive model (GAM). I used library(mgcv) to fit GAM.

    ################################
    ###Generalized Additive Model###
    ################################
    gm1 <- gam(adN ~ s(GC3), data = train.data)

This is a humble request that it will be an immense help if someone kindly let me know the solution of the above issue.

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467

1 Answers1

0

The easiest way to assess the fit of your models (in my opinion) is to plot the residuals of your GAM against the independent variable and visually inspect the results for heteroskedasticity. If there is any heteroskedasticity, the residuals of the model should spread out in the form of a cone/fan (i.e. there will be more spread in the residuals as the independent variable increases). You can obtain the residuals for the GAM and the LM usings the command resid(your_model).