我是 R 建模的新手,我遇到了用于建模的 GLM 函数。我对使用“二项式”族的逻辑回归感兴趣。我的问题是,当我的因变量可以采用两种可能的结果之一时——比如“正”、“负”——计算估计的默认结果是什么——模型预测“正”或“负”的对数几率默认为“负面”结果?此外,当因变量为
是
或否
- 1 或 2
通过
或失败
等?
是否有 R 选择此默认值的规则?有没有办法手动覆盖它?请澄清。
最佳答案
详见?binomial
:
For the ‘binomial’ and ‘quasibinomial’ families the response can be specified in one of three ways:
As a factor: ‘success’ is interpreted as the factor not having the first level (and hence usually of having the second level). added note: this usually means the first level alphabetically, since this is how R defines factors by default.
As a numerical vector with values between ‘0’ and ‘1’, interpreted as the proportion of successful cases (with the total number of cases given by the ‘weights’).
As a two-column integer matrix: the first column gives the number of successes and the second the number of failures.
因此预测的概率是“成功”的概率,即因子的第二个水平的概率,或者在数字情况下为 1 的概率。
从你的例子:
- 是或否:默认将“否”视为失败(因为按字母顺序排列),但您可以使用
my_data$my_factor <- relevel(my_data$my_factor,"Yes")
使"is"成为第一级。 - 1 或 2:这将失败或产生虚假结果。要么将变量变成一个因子(“1”将被视为第一级),要么减去 1 得到一个 0/1 变量(或者如果你希望 2 被视为失败,则使用
2-x
) - 通过或失败:参见“是或否”...
关于r - 用于逻辑回归的 GLM 函数 : what is the default predicted outcome?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528184/