Skip to content

How to get result of regression? #1786

Answered by fundef1
fundef1 asked this question in Q&A
Discussion options

You must be logged in to vote

alright, very clear. thanks.
But in that case I might as well pull the regression from DuckDB (where the data lives anyway) instead of pulling in another lib in javascript. (although it did get fidgety dealing with the timestamps)

~~~js 
await sql`CREATE OR REPLACE TABLE byidx AS SELECT generate_series AS idx, trunc(random()*10)::INT AS val FROM generate_series(1, 25, 1)`;
const byidx = await sql `FROM byidx`;
const [{slope,intercept}] = await sql`SELECT regr_slope(val,idx) AS slope, regr_intercept(val,idx) as intercept FROM byidx`;
~~~ 
~~~js 
    Plot.plot({
    title: `val = idx * ${slope.toFixed(2)} + ${intercept.toFixed(2)}`,
    marks: [
        Plot.lineY(byidx, {stroke: "red", x: …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Fil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants