Rem*_*i.b 8 statistics r normal-distribution
是否存在允许寻找最佳(或最佳)变量转换的函数或包,以使模型的残差尽可能正常?
例如:
frml = formula(some_tranformation(A) ~ B+I(B^2)+B:C+C)
model = aov(formula, data=data)
shapiro.test(residuals(model))
Run Code Online (Sandbox Code Playgroud)
是否有一个函数可以告诉什么是some_transformation()优化残差正态性的函数?
你的意思是像Box-Cox转型?
library(car)
m0 <- lm(cycles ~ len + amp + load, Wool)
plot(m0, which=2)
Run Code Online (Sandbox Code Playgroud)

# Box Cox Method, univariate
summary(p1 <- powerTransform(m0))
# bcPower Transformation to Normality
#
# Est.Power Std.Err. Wald Lower Bound Wald Upper Bound
# Y1 -0.0592 0.0611 -0.1789 0.0606
#
# Likelihood ratio tests about transformation parameters
# LRT df pval
# LR test, lambda = (0) 0.9213384 1 0.3371238
# LR test, lambda = (1) 84.0756559 1 0.0000000
# fit linear model with transformed response:
coef(p1, round=TRUE)
summary(m1 <- lm(bcPower(cycles, p1$roundlam) ~ len + amp + load, Wool))
plot(m1, which=2)
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不是统计学中已解决的问题.@statquant建议的用户几乎是你能做的最好的,但它并非没有自己的陷阱.
需要注意的一件重要事情是,shapiro.test一旦获得合理的样本量(即数百个样本),对正常性的测试就会对变化非常敏感,因此您不应盲目依赖它们.
我自己,我把问题扔进了太难的篮子里.如果数据看起来不是正常分布的,那么我会尝试找到您想要对数据运行的统计信息的非参数版本.