# Line of best fit from Aggregate Table

**URL:** <https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121>\
**Category:** Questions\
**Tags:** aggregate\
**Created:** [August 20, 2025, 3:25pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121 "2025-08-20T15:25:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rydholm](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Rydholm](https://cl.desmos.com/u/Rydholm)\
**Post date:** [August 20, 2025, 3:25pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/1 "2025-08-20T15:25:06Z")

</div>

My students are completing the Vroom Car Task.

I want them to compile their data. I have the graph set to show all of the students data, but on the next screen I want desmos to take all the points and draw a line of best fit with the slope & y-intercept identified.

I have two different methods, but neither is compiling the data to draw an accurate line of best fit.

> **[Pull Back Data Vroom Car • Activity by Brielle Rydholm](https://classroom.amplify.com/activity/68a5c95dd2ba44971c78928f?utm_campaign=share&utm_content=activity)**
>
> by Brielle Rydholm

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [August 22, 2025, 12:35am UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/2 "2025-08-22T00:35:04Z")

</div>

I don’t see anything wrong… maybe because I’ve never tried creating a Line Of Best Fit in Desmos, but everything seems accurate and correct (especially your formula for the LOBF)

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [August 22, 2025, 1:46pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/3 "2025-08-22T13:46:20Z")

</div>

Have you tried it with multiple fake students? You can see in the graph if you reduce lists X and Y to a single element r\_1 is undefined due to the 0 denominator, but as soon as you add a second element it will have a defined value.

Side question: Is it your intent to only use the first entry of each student for the line of best fit? You can join your aggregate lists in the CL (or graph, but that will slow your graph down a little more).

```auto
H1 = aggregate(table11.cellNumericValue(1,1))
H2 = aggregate(table11.cellNumericValue(2,1))
H3 = aggregate(table11.cellNumericValue(3,1))
H4 = aggregate(table11.cellNumericValue(4,1))
joinedH = H1.join(H2).join(H3).join(H4)

numberList(`H_{join}`): joinedH

```

You can use the `.lastValue()` as you’ve used elsewhere if that’s your preference. I do think you’ll want to only enable your table button when it’s filled though, because if a student leaves a cell blank somewhere in the middle, then the coordinates get misaligned and throw off your data.

```auto
t = table11
contentList = [
   t.cellNumericValue(1,1),
   t.cellNumericValue(2,1),
   t.cellNumericValue(3,1),
   t.cellNumericValue(4,1),
   t.cellNumericValue(1,2),
   t.cellNumericValue(2,2),
   t.cellNumericValue(3,2),
   t.cellNumericValue(4,2)
]
disabled: contentList.any((el) => isUndefined(el))

```

---

<div class="post-metadata">

**Author:** ![Mike\_Gleeson](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mike_gleeson/32/650_2.png) [@Mike\_Gleeson](https://cl.desmos.com/u/Mike_Gleeson)\
**Post date:** [August 22, 2025, 9:47pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/4 "2025-08-22T21:47:41Z")

</div>

I suspect Desmos isn’t able to consistently grab the correct x’s and y’s from an aggregate, essentially pairing up sets of x’s and y’s that aren’t really pairs at all, but do come from somewhere in the aggregate function. Down to a timing issue or registering the aggregate function I believe, since I’ve seen aggregate delay times of upwards of 30 seconds in some instances.

I posted about this here a while back: [Aggregation Plot Errors](https://cl.desmos.com/t/aggregation-plot-errors/7549)

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [August 24, 2025, 12:40am UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/5 "2025-08-24T00:40:09Z")

</div>

> [@Daniel\_Grubbs](#):
>
> `disabled: contentList.any((el) => isUndefined(el))`

But won’t that just disable the whole table for the student if that have one empty cell?

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [August 24, 2025, 2:05pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/6 "2025-08-24T14:05:03Z")

</div>

I may have been unclear. That CL is for the button, but is pulling information from the table.

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [August 24, 2025, 8:00pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/7 "2025-08-24T20:00:56Z")

</div>

Ohh!!! I see… that makes more sense if it’s for the button.

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [September 18, 2025, 6:17pm UTC](https://cl.desmos.com/t/line-of-best-fit-from-aggregate-table/8121/8 "2025-09-18T18:17:15Z")

</div>

A followup here. I brought this up with some engineers I know work with the aggregate function. They said that any misalignments are likely the result of incomplete entries. One way to avoid this is to use a placeholder value. I believe what you (@Mike_Gleeson ) were attempting to do was have an NaN value to basically exclude that point. (Are those also excluded from best fit calculations?) However, the way you coded it would only exclude the current student’s point from _their_ graph, but it would still collect (without the undefined value) for the aggregate lists; thus misaligning the lists. I’ll post detail and a fix in your prior post.
