0

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

This is my model:

convicted.1<-lm(Convicted~Misery,data=crime)

I've checked for NA/NaN/Inf.

This is my data:

 Year      Misery Convicted
1  1980  2.28061887   125,579
2  1981  2.39028147   135,478
3  1982  2.28851102    88,967
4  1983 -0.02460972    81,839
5  1984  1.08692707    80,928
6  1985  2.21803334    81,450
7  1986  2.76205545    81,695
8  1987  1.11823516    85,961
9  1988  0.74664507    97,726
10 1989  1.86235014   103,099
11 1990  1.68633217    80,239
12 1991  1.94113374    82,507
13 1992  2.03899643    78,682
14 1993  1.70617749    80,165
15 1994  1.43199034    81,516
16 1995  0.66847446    81,954
17 1996  0.57061177    81,792
18 1997  0.41413262    74,419
19 1998  0.68824315    76,789
20 1999  0.43373274    75,664
21 2000  0.76627584    74,064
22 2001  0.06166759    74,406
23 2002  0.19863856    73,876
24 2003 -0.25155123    77,079
25 2004 -0.31036692    79,308
26 2005 -0.29082809    78,520
27 2006 -0.40824492    81,972
28 2007 -0.36913663    88,402
29 2008 -0.17338061    95,072
30 2009  0.29657787    99,770
31 2010  0.84458438    95,403
32 2011  0.33574746    87,139
33 2012  0.35539356    81,155
34 2013  0.25745425    74,717
35 2014 -0.09487286    68,775
36 2015 -0.23185916    63,683
37 2016 -0.07533404    64,566
38 2017 -0.17324269    64,360
39 2018 -0.31030562    60,627
40 2019 -0.38861415    56,973
41 2020 -0.29069017    51,847
42 2021  0.27670191    45,774

Read previous solutions - emphasis on the NaN and Inf issue, and also use of non-numeric values - not an issue here

neilfws
  • 32,751
  • 5
  • 50
  • 63
Stew
  • 1
  • 1
  • 2
    The values for `Convicted` contain commas, so I would guess that the variable is of type character instead of type numeric. See what `str(crime)` says. You need either to change how the data is read into R to ensure the correct type, or convert the values to numeric: something like `crime$Convicted <- as.numeric(gsub(",", "", crime$Convicted))`. – neilfws Jun 22 '23 at 03:31

0 Answers0