本文介绍了使用 R 的 Proc GLM (SAS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试我应该在我的模型中包含哪些影响以对奶牛进行遗传评估.在 SAS 中,我会使用 proc GLM.SAS 代码将是:

I need to test which effects I should include in my model for genetic evaluation of cows. In SAS I would use a proc GLM. The SAS code would be:

data paula1; set paula0;
proc glm;
class year herd season;
model milk= year herd season age age*age;
run;

我的 R 代码是:

model1 = glm(milk ~ factor(year) + factor(herd) + factor(season) + age + I(age^2), data=paula1)
anova(model1)

我怀疑有什么问题,因为所有影响都具有统计显着性,即使我包括了与特征无关的其他影响.我不再有 SAS 许可证来比较结果.我在 R 中的代码正确吗?R 中的 glm 是否呈现类型 3 的平方和(对于 SAS 中呈现的不平衡数据)?在这种情况下使用lm有什么区别吗?提前致谢.宝拉

I suspect that there is something wrong because all effects are statistically significant, even when I include other effects that are not related to the trait. I do not have a SAS license anymore to compare the results. Is my code in R correct? Does glm in R presents the type 3 sum of squares (for unbalanced data as presented in SAS)? Is there any difference in this case for using lm?Thanks in advance.Paula

推荐答案

这是 SAS 和 R 用户之间非常常见的错误.

This is a very common error between SAS and R users.

SAS 中的 glm 包与 R 中的 glm 函数不同,我在下面解释.

The glm package in SAS is different to the glm function in R and I explain below.

这个 是来自官方网站的 SAS:GLM 程序使用最小二乘法来拟合一般线性模型".SAS 中的 GML 是 General Linear Models 的简称.这些与广义线性模型完全不同,后者是 R 中的 GML 函数计算的.

This is for SAS from the official site: "The GLM procedure uses the method of least squares to fit general linear models". The GML in SAS in short for General Linear Models. These are completely different to the Generalized Linear Models which is what the GML function in R calculates.

这个 用于 R 中的 glm 函数:"广义线性模型与普通线性模型一样容易拟合 R.事实上,它们只需要一个额外的参数来指定方差和链接函数.拟合广义线性模型的基本工具是glm函数,其一般结构如下:

This is for the glm function in R: " Generalized linear models are just as easy to fit in R as ordinary linear model. In fact, they require only an additional parameter to specify the variance and link functions.The basic tool for fitting generalized linear models is the glm function, which has the folllowing general structure:

glm(formula, family, data, weights, subset, ...)"

一般来说,一般线性模型使用普通最小二乘法进行参数估计,而广义线性模型使用最大似然估计进行参数估计.广义线性模型还允许线性模型通过链接函数与响应变量相关,并允许每个测量的方差大小成为其预测值的函数.(取自维基百科 这里)"

In general, general linear models use the ordinary least squares method for parameter estimation, whereas the generalized linear models use the maximum likelihood estimation for parameter estimation. Generalized linear models also "allow the linear model to be related to the response variable via a link function and allow the magnitude of the variance of each measurement to be a function of its predicted value. (taken from wikipedia here)"

要结束我的长篇演讲,您需要使用 lm 函数,对于方差分析表,它会给您与 SAS 中的 GLM 包相同的结果.对于 III 类错误,请检查 joran 和 BondedDust 的准确注释.

To end my long speech what you need to use is the lm function in R which as for the ANOVA table will give you the same results as the GLM package in SAS. For the type III error check the accurate comments of joran and BondedDust.

希望有帮助!

这篇关于使用 R 的 Proc GLM (SAS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:19