• Register
1 vote
2.7k views

Problem :

I want to perform a logistic regression but I am facing following error I am unable to find my mistake.

summary(glm(prefmerkel~angst+crisismerkel+leadership+trustworthiness+ideology+pid+agegroups+gender+region,data=gles))
Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  : 
  NA/NaN/Inf in 'y'
In addition: Warning messages:
1: In Ops.factor(y, mu) : ‘-’ nicht sinnvoll für Faktoren
2: In Ops.factor(eta, offset) : ‘-’ nicht sinnvoll für Faktoren
3: In Ops.factor(y, mu) : ‘-’ nicht sinnvoll für Faktoren
6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

The most important thing here is you can not have factor/categorical response variables.

For e.g.:

> d=data.frame(f=factor(c(1,2,1,2,1,2)),x=runif(6))
> glm(f~x,data=d)
Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 0.351715633412823, 0.449422287056223,  : 
  NA/NaN/Inf in 'y'
In addition: Warning messages:
1: In Ops.factor(y, mu) : - not meaningful for factors
2: In Ops.factor(eta, offset) : - not meaningful for factors
3: In Ops.factor(y, mu) : - not meaningful for factors

So if  you really want to do a logistic regression you must change them to 0 and 1OR FALSE and TRUE, and you must use family=binomial as follows:

For e.g.:

d$f=d$f=="2"
glm(f~x,data=d,family=binomial)
Call:  glm(formula = f ~ x, family = binomial, data = d)
Coefficients:
(Intercept)            x  
    -0.9066       1.8922  
Degrees of Freedom: 5 Total (i.e. Null);  4 Residual
Null Deviance:      8.318 
Residual Deviance: 8.092    AIC: 12.09

 

9 7 4
38,600 points

Related questions

0 votes
1 answer 75 views
75 views
Problem: This is my problem: Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, : na/nan/inf in 'y' Any help.
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
1 answer 1.5K views
1.5K views
Problem : Suppose I have data.frame a And I am using following code m.fit <- lm(col2 ~ col3 * col4, na.action = na.exclude) Here the col2 has some NA values And col3,col4 have values less than 1. I am getting following error: Error in lm.fit ... because of the NAs. Problem with this warning is interpreted by every google results is pointing towards the NA values. Have I misinterpreted the error ?
asked Nov 22, 2019 peterlaw 6.9k points
0 votes
1 answer 255 views
255 views
Problem : I have done a lot of research on this extensively without finding any solution on it. I have tried cleaning my data set as follows: library("myraster") impute.mean <- function(l) replace(l, is.na(l) | is.nan(l) | is.infinite(l) , mean(l, na.rm = TRUE)) losses <- ... TRUE, na.rm=TRUE, nan.rm=TRUE) All my research says it should be NA's or Inf's or NaN's in the data but I don't have any
asked Dec 5, 2019 alecxe 7.5k points
1 vote
1 answer 401 views
401 views
Problem: I have very fundamental knowledge of logistic regression. I am trying to write code on logistic regression. I have done a lot of research on this issue but because of my limited knowledge I am still unable to fix the below error. Error ... (data) stock.direction <- data$Direction training_model=glm(stock.direction~data$lag2,data=data,family=binomial) Please help me in fixing above error.
asked May 26, 2020 Martin K 6.6k points
1 vote
1 answer 1.1K views
1.1K views
Problem : Currently I am learning r. I have the data table "normal" which has the numeric as far as I know normalized values. If I try to execute the below command k <- kmeans(normal,center=3) Then I always face the below error: &ldquo;Error in do_one(nmeth) : NA/NaN/ ... call (arg 1)&rdquo; I am trying to fix it by researching on it but still unable to fix it. Can somebody help me in fixing it?
asked Mar 28, 2020 morrisBson 3.2k points
0 votes
1 answer 55 views
55 views
Problem: Why I got the error : Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-na) cases.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 3.5K views
3.5K views
Problem : While I am trying to run the boxcox transformation with the following code urban1 <- subset(ski,urban <= 4,na.rm=TRUE) ski$gender <- as.numeric((as.character(ski$gender)),na.rm=TRUE) urban1 <- as.numeric((as.character(urban1))) a <- (ski$gender*urban1) ... -> boxcar -> boxcar.formula -> lm -> lm.fit Execution halted Please let me know if anyone knows the solution for this error message.
asked Nov 27, 2019 alecxe 7.5k points
0 votes
1 answer 3 views
3 views
Problem: I want to use a logistic regression to actually perform regression and not classification. My response variable is numeric between 0 and 1 and not categorical. This response variable is not related to any kind of binomial process. In particular, there is no "success", no " ... , looking at the maths, it seems like the log-likelihood still makes sense with $y_i$ in $[0, 1]$. Am I wrong?
asked 4 days ago padma1 34.3k points
0 votes
1 answer 6 views
6 views
Problem: I did a logistic regression: EW <- glm(everwrk~age_p + r_maritl, data = NH11, family = "binomial") Moreover, I want to predict everwrk for each level of r_maritl. r_maritl has the following levels: levels(NH11$r_maritl) "0 Under 14 years" "1 Married - spouse in household" "2 Married - spouse ... 2 2 ... str(NH11$r_maritl) Factor w/ 10 levels "0 Under 14 years",..: 6 8 5 7 2 2 8 8 8 2 ...
asked Apr 24 Humaira ahmed 50.7k points
0 votes
1 answer 5 views
5 views
Problem: I am really new to RStudio and desperately trying to get to grips with it all, so I apologise if this is a silly question. I am trying to generate a heatmap for my RNA Seq Data set using pheatmap, however I am coming up again a number of errors. My data looks like this: ... 2.32 3.45 3.74 ... $ p_value : num 0.00045 0.0006 0.0006 0.00005 Thank you and I look forward to your responses.
asked 4 days ago Yeamin 21.4k points