我的数据集可以在这里找到:https://raw.githubusercontent.com/yuliaUU/test/main/test.csv
library(gamlss)
library(tidyverse)
data_final<- read_csv("https://raw.githubusercontent.com/yuliaUU/test/main/test.csv")
# Normal model with log transformation
model_1 <- gamlss(log(Abundance) ~ salinity*avrg_dep, data = data_final, family = NO())
# log normal model
model_2 <- gamlss(Abundance ~ salinity*avrg_dep, data = data_final, family = LOGNO())
# Model with inverse gaussian distribution
model_3 <- gamlss(Abundance ~ salinity*avrg_dep, data = data_final, family = IG())
# Gamma model
model_4 <- gamlss(Abundance ~ salinity*avrg_dep, data = data_final, family = GA())
我想用GAIC来比较模型之间的差异,但第一个模型的GAIC值与其他模型相差甚远
我读到:
为确保具有转换响应的线性模型的GAIC相当,使用转换对数似然乘以雅可比矩阵,并手动重新计算GAIC。
我试着用下面的方法来做:
Jacobian <- 1/abs(data_final$Abundance)
# Calculate fitted values (on the log scale)
fitted_values_log <- predict(model_1)
# Calculate residuals manually (on the log scale)
residuals_transformed <- log(data_final$Abundance) - fitted_values_log
# Calculate standard deviation of the residuals
sd_residuals_transformed <- sd(residuals_transformed)
# Transformed log-likelihood calculation
log_likelihood_transformed <- sum(dnorm(log(data_final$Abundance), mean=fitted_values_log, sd=sd_residuals_transformed, log=TRUE) * Jacobian)
# Calculate degrees of freedom: number of parameters in the model
df <- length(coef(model_1))
# Manually calculate GAIC
GAIC_transformed <- -2 * log_likelihood_transformed + 2 * df
GAIC_transformed
但是产生的价值太低了,所以我想我在某个地方犯了一个错误
2条答案
按热度按时间brccelvz1#
最简单的答案是在gamlss中显式拟合对数正态分布,即家族=LOGNO
一个更一般的答案,它适用于真实的线上的正态分布以外的分布,例如:TF,是创建相应的logTF分布:
gen.Family(“TF”,type=“log”)
然后在游戏中使用
家族=logTF
kh212irz2#