Error: "Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'y'"

Hi, I've actually had problems with using R I've tried to search for an online solution but I still can't fix it.

My error is:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :

NA/NaN/Inf in 'y'

In addition: Warning message:

In storage.mode(v) <- "double" : NAs introduced by coercion



> attach(dataset)

The following objects are masked from dataset (pos = 3):



Age, CGPA, Employment, games, Gender, handwriting, height, relationship, school,

weight

> mod1= lm(Gender~weight+height+games)

This is roughly how my dataset looks like:

> dataset

# A tibble: 160 x 10

Gender Age Employment school CGPA height weight relationship handwriting games

<chr> <dbl> <chr> <chr> <dbl> <dbl> <dbl> <chr> <dbl> <dbl>

1 Male 19 A student Mckl 3.75 175 60 Single 7 20

2 Female 17 A student Mckl 3.16 165 53 Single 7 10

3 Male 19 A student Taylors ~ 4 175 72 Single 5 6

4 Female 19 A student Methodis~ 3.2 160 53 Taken 3 6

5 Female 19 A student MCKL 3 165 48 Taken 5 6

6 Female 18 A student Methodis~ 3.33 164 70 Single 10 8

7 Female 19 A student Methodis~ 3.58 157 41 Single 5 4

8 Male 19 A student MCKL 3.71 167 64 Taken 3 35

9 Male 20 A student MCKL 4 170 70 Single 5 60

10 Female 18 A student MCKL 3 161 45 Taken 7 6

# ... with 150 more rows

There are a couple of ways to get this error, but I think the issue here is you are regressing over a character vector. Gender is characters "Male" or "Female".

You want to convert that into a numerical variable, 1 or 0 for one gender.

Here's a reprex for that kind of error (and for future reference you'll want to pose questions about coding errors like this with a reprex)

library(dplyr)
df <- tibble(
  y = LETTERS[1:3],
  x1 = 1:3,
  x2 = 3:5
)
lm(y ~ x1 + x2, data = df)
#> Warning in storage.mode(v) <- "double": NAs introduced by coercion
#> Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...): 
#>   NA/NaN/Inf in 'y'

Created on 2022-03-26 by the reprex package (v2.0.1)

Do be careful about how you interpret your results! I don't think weight, height or games will do anything to correctly predict or explain one's gender.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.