Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

I'm trying to run a logistic regression on R and am getting this error

model <- glm(morning ~ time since arrival this dry season (days).,family=binomial(link='logit'),data=raw_data_1) Error: unexpected symbol in "model <- glm(morning ~ time since"

below are the heading for my data:
Bear ID/ Date DMY/ sighting occurred in morning (0/1)/ time since arrival this dry season (days)

this is a sample of my data:

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"))

I'm trying to carry out a logistic regression to model the probability of being seen in the morning relative to time since arrival this dry season. Massive R rookie, first model I have had to make.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try with this as mentioned in comments:

#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)

Output:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...