1
$\begingroup$

I have a data.frame that have two cols, $x=mz$ and $y=res$. There are about ~2 million rows in the DF. When I plot the graph I get the below.Scatterplot

What I'd like to do is find a way to define two quadratics to fit to get the two curves badly sketched in orange. it would be nice to be able to do it in ggplot. I have tried to fit a stat_smooth but I haven't been able to come close to the result I want.

plot <- ggplot(data=df, aes(mz, res)) + geom_point()
plot + stat_smooth(method = "lm", formula = y ~ I(x^-2) - x)

enter image description here Apologies if this is something really trivial and obvious, but I am not a data scientist and I am just trying to help a friend.

$\endgroup$

1 Answer 1

1
$\begingroup$

You could try quantile regression using a "generalised additive" model. With R you could use the qgam package, I guess. What you need to do is to estimate a model for upper/lower values of the distribution. The figure below shows a plot from the qgam vignette linked above.

enter image description here

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.