Here's some high school geometry then ;-)
# First two models
df1 <- data.frame(x=1:50, y=1:50/2+rnorm(50)+10)
m1 <- lm(y~x, df1)
df2 <- data.frame(x=1:25, y=25:1*2+rnorm(25)-10)
m2 <- lm(y~x, df2)
# Plot them to show the intersection visually
plot(df1)
points(df2)
# Now calculate it!
a <- coef(m1)-coef(m2)
c(x=-a[[1]]/a[[2]], y=coef(m1)[[2]]*x + coef(m1)[[1]])
Or, to simplify the solve
-based solution by @Dwin:
cm <- rbind(coef(m1),coef(m2)) # Coefficient matrix
c(-solve(cbind(cm[,2],-1)) %*% cm[,1])
# [1] 12.68034 16.57181
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…