Inconsistent regressions/intersections (manually reading summary.lm() versus a function)

I'm comparing the regressions of death counts (y) versus time (x), between 2 sexes. Reading summary.lm() gives me a set of regressions:
For females: [deaths = (-101.98 * year) + 241813.24]
For males: [deaths = (778.9 * year) - 1,526,000]

#summary of the female model
summary.lm(model.USdiabetes_F)
#summary of the male model
summary.lm(model.USdiabetes_M)
#which returns...

When I plug those regressions into Desmos or MathPapa, they intersect at x = 2006.87. But I also used an rstudio function provided by a user in this thread.

# Linear model Intercept function
lmIntx <- function(fit1, fit2, rnd=2) {
  b1<- fit1$coefficient[1]  #y-int for fit1
  m1<- fit1$coefficient[2]  #slope for fit1
  b2<- fit2$coefficient[1]  #y-int for fit2
  m2<- fit2$coefficient[2]  #slope for fit2
  if(m1==m2 & b1==b2) {print("Lines are identical")
  } else if(m1==m2 & b1 != b2) {print("Lines are parallel")
  } else {
    x <- (b2-b1)/(m1-m2)      #solved general equation for x
    y <- m1*x + b1            #plug in the result
    data.frame(x=round(x, rnd), y=round(y, rnd))
  }
lmIntx(lm(rawUSdiabetes_M$FactValueNumeric~rawUSdiabetes_M$Period), 
lm(rawUSdiabetes_F$FactValueNumeric~rawUSdiabetes_F$Period))
#which gave me...

x = 2007.41, y = 37287.32

Please tell me what's going on; it would be much appreciated.

Data

For reproduction purposes, here's my data. Bc how the data is arranged, in practice I subset male and female deaths into separate datasets (thus filenames like "model.USdiabetes_F").

Period / FactValueNumeric / sexCat
2019 38340 Female
2019 49433 Male
2018 37867 Female
2018 47795 Male
2017 37505 Female
2017 46703 Male
2016 36566 Female
2016 44129 Male
2015 36580 Female
2015 43122 Male
2014 35645 Female
2014 41262 Male
2013 36160 Female
2013 40098 Male
2012 35901 Female
2012 38933 Male
2011 36093 Female
2011 38719 Male
2010 34155 Female
2010 35895 Male
2009 34256 Female

Would Analysis of Variance allow you to compare the relationship between two variables for two groups?

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.