Jump to content

How to force a straight line of best fit through the origin.


Sophie Osborne

Recommended Posts

I'm wanting to plot a straight line of best fit onto some scatter plots. I can do this quite easily using the straight line option in lines and curves, however it won't necessarily go through the origin, which I need it to do. I am wanting it to be able to change as I apply filters, so I can't just use the curve draw option, with a set slope (i.e y=bx). I am thinking that I would need to use either a data function or expression function. Is this possible and if so how
Link to comment
Share on other sites

You can achieve this with a data function. The function will take your filtered data as input. The output could be a new table with the original values and the simulated values from the regression.

You can use the nls() function instead of the lm() function in R to force the intercept to 0.

See an example here:

https://alvaroaguado3.github.io/forcing-regression-coefficients-in-r-par...

If a regular linear regression on your data has an intercept that is already very close to 0 you could also run the lm() function to extract the slope. This would shift your line slightly. I can't estimate this effect without knowing your data.

If you have never worked with data functions before you can watch two little video tutorials that I posted here:

https://community.spotfire.com/questions/self-referential-calculated-column

https://community.spotfire.com/questions/adding-value-previous-row-current-...

You might find more tutorials in youtube or other places

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...