【问题标题】:I'm trying to run a logistic regression on R and am getting this error我正在尝试对 R 进行逻辑回归并收到此错误
【发布时间】:2021-01-12 16:26:17
【问题描述】:

模型

以下是我的数据的标题:
熊身份证/ 日期 DMY/ 目击发生在早上 (0/1)/ 本旱季到达后的时间(天)

这是我的数据样本:

dput(head(raw_data_1,10))

structure(list(`Bear ID` = c("Cobalt", "Pazu", "Fang", "McQueen", 
"Mushroom", "Umber", "Umber", "Fang", "Teto", "Eggplant"), `Date DMY` = structure(c(1463011200, 
1464480000, 1464825600, 1464825600, 1465084800, 1466380800, 1466467200, 
1467590400, 1468886400, 1470182400), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), `sighting occurred in morning (0/1)` = c(0, 1, 1, 
0, 0, 1, 1, 0, 1, 1), `time since arrival this dry season (days)` = c(72, 
89, 93, 93, 96, 111, 112, 125, 140, 155)), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))

我正在尝试进行逻辑回归,以模拟在这个旱季到达以来相对于时间的早晨被看到的概率。 Massive R 菜鸟,我必须制作的第一个模型。

【问题讨论】:

  • 对带有空格的列名使用引号',例如'本旱季到达后的时间(天)'

标签: r logistic-regression glm


【解决方案1】:

按照 cmets 中的说明尝试一下:

#Code
glm(raw_data_1$'sighting occurred in morning (0/1)' ~
      raw_data_1$'time since arrival this dry season (days)',
    family=binomial(link='logit'),data=raw_data_1)

输出:

Call:  glm(formula = raw_data_1$"sighting occurred in morning (0/1)" ~ 
    raw_data_1$"time since arrival this dry season (days)", family = binomial(link = "logit"), 
    data = raw_data_1)

Coefficients:
                                           (Intercept)  
                                              -4.17519  
raw_data_1$"time since arrival this dry season (days)"  
                                               0.04337  

Degrees of Freedom: 9 Total (i.e. Null);  8 Residual
Null Deviance:      13.46 
Residual Deviance: 11.58    AIC: 15.58

【讨论】:

  • 谢谢你 Duck - 虽然它提出了这个:model.frame.default 中的错误(公式 = raw_data_1$morning ~ raw_data_1$"这个旱季到达的时间(天)。",:无效变量“raw_data_1$morning”的类型(NULL)此外:警告消息:1:未知或未初始化的列:morning。2:未知或未初始化的列:time since arrival this dry season (days).
  • 能否请您使用dput(raw_data_1) 并将输出粘贴到您的问题中以重现您的问题?
  • 你想让我将所有数据粘贴到问题中吗?
  • @LLLLFFFF 只是一个使用dput(head(raw_data_1,10))的示例
  • 这就是你想要的吗?
猜你喜欢
  • 2021-04-06
  • 2019-11-22
  • 1970-01-01
  • 2021-02-16
  • 2017-04-29
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 2018-01-26
相关资源
最近更新 更多