I was wondering if the following method/code is suitable for performing the validation test for a GAMLSS model. If yes (if not, please modify the code), how would you decide whether the mode is appropriate or not based on the results? Thanks so much for your time and advice in advance.
library(tidyverse)
df=read.csv("https://raw.githubusercontent.com/kinokoberuji/R-Tutorials/master/LMSmodelGAMLSS.csv", sep=";")%>%as_tibble()
set.seed(1)
#use 70% of dataset as training set and 30% as test set
sample <- sample(c(TRUE, FALSE), nrow(df), replace=TRUE, prob=c(0.7,0.3))
train <- df[sample, ]
test <- df[!sample, ]
m1<-gamlss(TLC ~ Height + pb(Age), sigma.fo = ~pb(Age), nu.fo = ~(Age), family = BCCGo(mu.link = "identity"),data=train)
y_pred <-predict(m1,newdata=test,type="response")
y_true <- test$TLC
MAE <- sum(abs(y_true-y_pred))/length(y_true) # Mean Absolute Error
MSE <- sum((y_true-y_pred)^2)/length(y_true) # Mean Squared Error
MAPE <- 100*sum(abs(y_true-y_pred)/y_true)/length(y_true) # Mean Absolute Percentage Error
R2 <- 1-MSE/var(y_true)
list(MAE=MAE,
MSE=MSE,
MAPE=MAPE,
R2= R2)
There are functions avbailab le in gamlss for validation and testing, See Stasinopoulos et al. (2017) page 407.401-