# Intercpt between two lines

Hi guys,

I really need help!
I have to compare two lines and find out the intercept, but i have just the data, i do not have a line equation, so i must have the equation and after find the intercept?

Someone can help?
Hz BRA1 BRA11
1 0.03 12.74 12.25
2 0.05 18.65 15.73
3 0.07 22.05 17.86
4 0.10 26.71 19.92
5 0.20 35.20 24.65
6 0.50 50.46 31.19
7 1.00 64.68 36.31
8 1.13 67.32 37.20
9 5.00 105.98 46.88
10 10.00 126.71 50.64
11 15.00 139.62 52.48
12 20.00 149.33 53.90
13 33.00 164.31 55.88

The two lines must be Hz ~BRA1 and Hz ~BRA11

Have you plotted the data? I'm not sure this data is actually linear so won't have an equation of a line.

``````library(tidyverse)

datin <- tribble(
~Row, ~Hz, ~BRA1, ~BRA11,
1, 0.03, 12.74, 12.25,
2, 0.05, 18.65, 15.73,
3, 0.07, 22.05, 17.86,
4, 0.10, 26.71, 19.92,
5, 0.20, 35.20, 24.65,
6, 0.50, 50.46, 31.19,
7, 1.00, 64.68, 36.31,
8, 1.13, 67.32, 37.20,
9, 5.00, 105.98, 46.88,
10, 10.00, 126.71, 50.64,
11, 15.00, 139.62, 52.48,
12, 20.00, 149.33, 53.90,
13, 33.00, 164.31, 55.88)

dat <- datin %>%
select(-Row) %>%
pivot_longer(cols=starts_with("BRA"))

dat %>%
ggplot(aes(x=Hz, y=value, group=name, colour=name)) +
geom_point()+
geom_line()
``````

Created on 2020-02-04 by the reprex package (v0.3.0)

Tksss! You simplified a lot what i was think, the only part i really need is know in which point they intercept. It is between 0,03 and 0,05, but i need to return a value

It looks like the curves are very linear in that range. Just make linear regressions for both lines in that area only and solve them algebraically (easy) or in r. It won't be an exact answer but maybe close enough. You'll have to decide that.

Bill Bentley

I would like to do it in code because i have to do it 90 times for 90 different groups!
But i guess it is the only away, i've been look at it on internet for 2 days and the only thing i could find is how to do a linear regression

Tks for the help and your time <3

These curves, in your example, never intersect. As I zoom in, I see that. I was looking for the point where BRA1 was less than BRA11 but it never happens so they don't intersect. To find the range of intersection, I was going to look for the change point of where one increases over the other but that just doesn't happen in this example.

``````library(tidyverse)

datin <- tribble(
~Row, ~Hz, ~BRA1, ~BRA11,
1, 0.03, 12.74, 12.25,
2, 0.05, 18.65, 15.73,
3, 0.07, 22.05, 17.86,
4, 0.10, 26.71, 19.92,
5, 0.20, 35.20, 24.65,
6, 0.50, 50.46, 31.19,
7, 1.00, 64.68, 36.31,
8, 1.13, 67.32, 37.20,
9, 5.00, 105.98, 46.88,
10, 10.00, 126.71, 50.64,
11, 15.00, 139.62, 52.48,
12, 20.00, 149.33, 53.90,
13, 33.00, 164.31, 55.88)

dat <- datin %>%
select(-Row) %>%
pivot_longer(cols=starts_with("BRA"))

dat %>%
filter(Hz<=.07) %>%
ggplot(aes(x=Hz, y=value, group=name, colour=name)) +
geom_point()+
geom_line()
``````

Created on 2020-02-04 by the reprex package (v0.3.0)

And if we find a linear regression, that give us a functions and after we could see with this function before 0.03, were maybe they intercept?

Can we do it?

It's generally not advised to predict data outside your range and this isn't linear data. You could fit some curve to the data and extrapolate to less than 0.03 but this, again, isn't advised.

Assuming that graph is right (I didn't duplicate it), each curve looks like two segmented linear equations. The two bottom segments definitely intersect but not between .03 and .05. You can solve the two lower segment equations in r and loop through all 90 of your groups, probably using matrices. No need to sharpen a pencil! As for extrapolating curves, I agree it's not generally advised but it's done successfully all the time IF the process that generates them is well understood and the subject matter experts do not expect any surprises, like other segments, or surprise nonlinearities. Extrapolation is not a theoretical limitation, it's a practical, application oriented one.

Bill

It is a logarithmic correlation!

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