简体   繁体   English

GLM输出中缺少一级因子

[英]One level of factor missing from GLM output

I'm creating a model to investigate main effects and interactions between the total no of sharks ~ Month + SST + Sex. 我正在创建一个模型来研究鲨鱼总数〜月+ SST +性别之间的主要影响和相互作用。 When I create the model for this test, the output only shows SexMale and not Sexfemale. 当我为此测试创建模型时,输出仅显示SexMale,而不显示Sexfemale。

I understand one predictor is the intercept which has been accounted for, but Sexfemale does not appear when modelled alongside SST. 我了解一个预测因素是已经考虑的拦截,但是与SST一起建模时,不会出现Sexfemale。 Is there something I am missing? 我有什么想念的吗?

The output is correct. 输出正确。 If you have a factor variable, glm always uses n-1 interactions. 如果您有因子变量,则glm始终使用n-1个交互。 In your case sexFemale is the baseline and sexMale will only be used if the sex variable = Male 在您的情况下,sexfemale是基准,而sexMale仅在性别变量= Male时使用

EDIT based on comment of op 根据op的评论进行编辑

I created a very small reproducible example. 我创建了一个非常小的可复制示例。

data <- data.frame(sharks = c(2,4,6,8,1,3,5,7),
                   season = c("spring", "spring", "summer", "summer", "autumn","autumn", "winter", "winter"),
                   sst = c(23,24,26,26,24,22,20,20),
                   sex = c("F", "F", "M", "M", "F", "M", "F", "F"))

# basic glm model
glm_mod <- glm(sharks ~ . , data = data)

Coefficients:
  (Intercept)  seasonspring  seasonsummer  seasonwinter  sst  sexM  
    -47             3            -4            13         2     6 

Interpretation: the baseline for the model is the autumn season and female sex. 解释:该模型的基准是秋季和女性。 In other words, if it is autumn and the shark(?) is female the number of sharks is -47 + 2 * the temperature . 换句话说,如果是秋天,并且shark(?)是雌性,则鲨鱼的数量为-47 + 2 * the temperature

baseline: autumn + female because they are the first levels of the factor. 基线:秋季+女性,因为他们是第一水平的因素。

glm formula:
-47 + 3 * spring + -4 * summer + 13 * winter + 2 * sst + 6 * M

glm model with interactions between season and sex: 性别和季节之间相互作用的glm模型:

# glm model with interactions
glm_mod_interact <- glm(sharks ~ sst + season:sex , data = data)

Coefficients:
  (Intercept)                sst  seasonautumn:sexF  seasonspring:sexF  seasonsummer:sexF  seasonwinter:sexF  seasonautumn:sexM  
-45                  2                 -2                  1                 NA                 11                  4  
seasonspring:sexM  seasonsummer:sexM  seasonwinter:sexM  
NA                 NA                 NA  

The NA's are there because there is no data in the example data.frame for these combinations. NA之所以存在,是因为示例data.frame中没有这些组合的数据。 But here you have all the interactions between sex and season. 但是在这里,您可以了解性别与季节之间的所有互动。 Whether this is significant you will have to figure out. 这是否重要,您必须弄清楚。

glm_mod_interact formula:
-45 + 2 * sst + -2 * seasonautumn:sexF + 1 * seasonspring:sexF + etc..

My advise is to read openintro statistics chapter 7 and further, or better yet, Data Analysis Using Regression and Multilevel/Hierarchical Models by Andrew Gelman and Jennifer Hill 我的建议是阅读openintro统计信息的第7章,或者更进一步,或者更好的是,Andrew Gelman和Jennifer Hill 撰写的《 使用回归和多层次/层次模型进行数据分析》。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM