R语言偏态分布的回归分析
•
编程语言
偏态分布的回归分析
回归是我们经常遇到的模型,但是回归会根据Y因变量的类型,分成分类问题(Y是分类变量,如生存或死亡)与回归问题(Y是连续性变量,如身高体重)。
在R里面,建立回归模型是通过family参数指定回归类型。其实也是根据Y的分布,来确定用何种family。
Family 种类
在lm()函数中,常见的family 有:
image.png
当然,回归方程中还有更多的family,但是不局限于函数。详细情况请见:https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/family
常见分布类型
一般我们做回归方程时候,碰见的常见回归类型有以下四种。最常见的是正态分布。
image.png
当然,我们遇到偏态分布时候,一般有两种处理方式。
- 通过将偏态数据进行log变换,转成正态分布进行回归。
- 直接使用 family=Gamma 指定Gamma分布。
案例
可使用glm()模型构建回归方程:

1.Logistic Regression
# where F is a binary factor and x1-x3 are continuous predictors fit <- glm(F~x1+x2+x3,data=mydata,family=binomial()) summary(fit) # display results confint(fit) # 95% CI for the coefficients exp(coef(fit)) # exponentiated coefficients exp(confint(fit)) # 95% CI for exponentiated coefficients predict(fit, type="response") # predicted values residuals(fit, type="deviance") # residuals
2.Poisson Regression
# Poisson Regression # where count is a count and x1-x3 are continuous predictors fit <- glm(count ~ x1+x2+x3, data=mydata, family=poisson()) summary(fit) display results
3.Gaussian Regression
# Gaussian Regression # where count is a count and x1-x3 are continuous predictors fit <- glm(count ~ x1+x2+x3, data=mydata) summary(fit) display results
4.Gamma Regression
# set linear regression model set.seed(1) x = rnorm(100) y = rgamma(100,10,3) glm(y ~ x, family = Gamma)
参考:
- https://www.statmethods.net/advstats/glm.html
- https://bookdown.org/ndphillips/YaRrr/regression-on-non-normal-data-with-glm.html
- https://stats.stackexchange.com/questions/58497/using-r-for-glm-with-gamma-distribution
- https://rpubs.com/kaz_yos/glm-Gamma
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/a6c4fdd035.html
