YouTube2Text

Linear Regression, Clearly Explained!!! — Transcript

by StatQuest with Josh Starmer · 3,687 words · 647 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Sailing on a boat headed towards
  2. 0:03StatQuest.
  3. 0:06Join me on this boat, let's go to
  4. 0:08StatQuest.
  5. 0:10It's super cool.
  6. 0:13Hello, and welcome to StatQuest.
  7. 0:16StatQuest is brought to you by the
  8. 0:18friendly folks in the genetics
  9. 0:19department at the University of North
  10. 0:21Carolina at Chapel Hill.
  11. 0:23Today, we're going to be talking about
  12. 0:25linear regression, aka general linear
  13. 0:28models part one. There's a lot of parts
  14. 0:31to linear models, but it's a really cool
  15. 0:33and powerful concept. So, let's get
  16. 0:36right down to it.
  17. 0:38I promise you, I have lots and lots of
  18. 0:40slides that talk about all the
  19. 0:42nitty-gritty details behind linear
  20. 0:44regression. But first, let's talk about
  21. 0:46the main ideas behind it.
  22. 0:49The first thing you do in linear
  23. 0:50regression is use least squares to fit a
  24. 0:53line to the data.
  25. 0:55The second thing you do is calculate R
  26. 0:58squared.
  27. 0:59Lastly, calculate a P value for R
  28. 1:02squared.
  29. 1:04There are lots of other little things
  30. 1:05that come up along the way, but these
  31. 1:08are the three most important concepts
  32. 1:10behind linear regression.
  33. 1:13In the StatQuest fitting a line to data,
  34. 1:16we talked about
  35. 1:18fitting a line to data. Duh.
  36. 1:21But let's do a quick review.
  37. 1:24I'm going to introduce some new
  38. 1:25terminology in this part of the video,
  39. 1:27so it's worth watching even if you've
  40. 1:29already seen the earlier StatQuest.
  41. 1:32That said, if you need more details,
  42. 1:34check that StatQuest out.
  43. 1:37For this review, we're going to be
  44. 1:39talking about a data set where we took a
  45. 1:41bunch of mice, and we measured their
  46. 1:43size, and we measured their weight.
  47. 1:46Our goal is to use mouse weight as a way
  48. 1:50to predict mouse size.
  49. 1:53First, draw a a through the data.
  50. 1:57Second, measure the distance from the
  51. 1:59line to the data. Square each distance,
  52. 2:02and then add them up.
  53. 2:05Terminology alert.
  54. 2:07The distance from the line to the data
  55. 2:08point is called a residual.
  56. 2:12Third, rotate the line a little bit.
  57. 2:16With the new line, measure the
  58. 2:18residuals, square them, and then sum up
  59. 2:21the squares.
  60. 2:23Now, rotate the line a little bit more.
  61. 2:27Sum up the squared residuals, etc.,
  62. 2:30etc., etc. We rotate, and then sum up
  63. 2:33the squared residuals. Rotate, then sum
  64. 2:35up the squared residuals. Just keep
  65. 2:37doing that.
  66. 2:39After a bunch of rotations, you can plot
  67. 2:42the sum of squared residuals and
  68. 2:44corresponding rotation.
  69. 2:46So, in this graph, we have the sum of
  70. 2:48squared residuals on the Y axis, and the
  71. 2:51different rotations on the X axis.
  72. 2:55Lastly, you find the rotation that has
  73. 2:58the least sum of squares.
  74. 3:00More details about how this is actually
  75. 3:03done in practice are provided in the
  76. 3:05StatQuest on fitting a line to data.
  77. 3:09So, we see that this rotation is the one
  78. 3:12with the least squares. So, it will be
  79. 3:15the one to fit to the data.
  80. 3:18This is our least squares rotation
  81. 3:21superimposed on the original data.
  82. 3:24Bam!
  83. 3:25Now, we know why the method for fitting
  84. 3:27a line is called least squares.
  85. 3:31Now, we have fit a line to the data.
  86. 3:33This is awesome.
  87. 3:36Here's the equation for the line.
  88. 3:38Least squares estimated two parameters.
  89. 3:43A Y axis intercept
  90. 3:46and a slope.
  91. 3:48Since the slope is not zero, it means
  92. 3:51that knowing a mouse's weight will help
  93. 3:53us make a guess about that mouse's size.
  94. 3:57How good is that guess?
  95. 4:00Calculating R squared is the first step
  96. 4:03in determining how good that guess will
  97. 4:06be.
  98. 4:07The StatQuest R squared explained talks
  99. 4:11about
  100. 4:12you got it R squared.
  101. 4:15Let's do a quick review.
  102. 4:17I'm also going to introduce some
  103. 4:19additional terminology. So, it's worth
  104. 4:21watching this part of the video even if
  105. 4:23you've seen the original StatQuest on R
  106. 4:25squared.
  107. 4:27First, calculate the average mouse size.
  108. 4:31Okay, I've just shifted all the data
  109. 4:34points to the Y axis to emphasize that
  110. 4:37at this point we are only interested in
  111. 4:40mouse size.
  112. 4:42Here, I've drawn a black line to show
  113. 4:45the average mouse size.
  114. 4:48Bam!
  115. 4:50Now, sum the squared residuals.
  116. 4:53Just like in least squares, we measure
  117. 4:56the distance from the mean to the data
  118. 4:58point and square it and then add those
  119. 5:01squares together.
  120. 5:04Terminology alert. We'll call this SS
  121. 5:07mean for sum of squares around the mean.
  122. 5:12Note,
  123. 5:13the sum of squares around the mean
  124. 5:15equals the data minus the mean squared.
  125. 5:20The variation around the mean equals the
  126. 5:22data minus the mean squared divided by
  127. 5:25n.
  128. 5:27N is the sample size. In this case, n
  129. 5:30equals 9.
  130. 5:32The shorthand notation is the variation
  131. 5:35around the mean equals the sum of
  132. 5:37squares around the mean divided by n,
  133. 5:40the sample size.
  134. 5:42Another way to think about variance is
  135. 5:45as the average sum of squares per mouse.
  136. 5:49Now, go back to the original plot and
  137. 5:52sum up the squared residuals around our
  138. 5:55least squares fit.
  139. 5:57We'll call this SS fit for the sum of
  140. 6:01squares around the least squares fit.
  141. 6:04The sum of squares around the least
  142. 6:06squares fit is the sum of the distances
  143. 6:10between the data and the line squared.
  144. 6:14Just like with the mean, the variance
  145. 6:17around the fit
  146. 6:18is the distance between the line and the
  147. 6:20data squared divided by n, the sample
  148. 6:24size.
  149. 6:25The shorthand is the variation around
  150. 6:28the fitted line equals the sum of
  151. 6:30squares around the fitted line divided
  152. 6:33by n, the sample size.
  153. 6:36Again, we can think of the variation
  154. 6:38around the fit as the average of the sum
  155. 6:41of squares around the fit for each
  156. 6:43mouse.
  157. 6:45In general, the variance of something
  158. 6:47equals the sum of squares divided by the
  159. 6:50number of those things.
  160. 6:52In other words, it's an average of sum
  161. 6:55of squares.
  162. 6:56I mentioned this because it's going to
  163. 6:58come in handy in a little bit, so keep
  164. 7:00it in the back of your mind.
  165. 7:03Okay, let's step back a little bit.
  166. 7:05This is the raw variation in mouse size.
  167. 7:10And this is the variation around the
  168. 7:12least squares line.
  169. 7:14There is less variation around the line
  170. 7:16that we fit by least squares. That is to
  171. 7:19say, the residuals are smaller.
  172. 7:22As a result, we say that some of the
  173. 7:25variation in mouse size is explained by
  174. 7:28taking mouse weight into account.
  175. 7:31In other words, heavier mice are bigger,
  176. 7:35lighter mice are smaller.
  177. 7:37R squared tells us how much of the
  178. 7:40variation in mouse size can be explained
  179. 7:43by taking mouse weight into account.
  180. 7:47This is the formula for R squared. It's
  181. 7:50the variation around the mean minus the
  182. 7:52variation around the fit divided by the
  183. 7:55variation around the mean.
  184. 7:58Let's look at an example.
  185. 8:00In this example,
  186. 8:02the variation around the mean equals
  187. 8:0411.1
  188. 8:06and the variation around the fit equals
  189. 8:084.4.
  190. 8:10So, we plug those numbers into the
  191. 8:12equation.
  192. 8:13The result is that R squared equals 0.6,
  193. 8:18which is the same thing as saying 60%.
  194. 8:22This means there is a 60% reduction in
  195. 8:26the variance when we take the mouse
  196. 8:28weight into account.
  197. 8:30Alternatively,
  198. 8:32we can say that mouse weight explains
  199. 8:3460% of the variation in mouse size.
  200. 8:39We can also use the sum of squares to
  201. 8:41make the same calculation.
  202. 8:43This is because when we're talking about
  203. 8:45variation, everything's divided by n,
  204. 8:48the sample size. Since everything's
  205. 8:50scaled by n, we can pull that term out
  206. 8:53and just use the raw sum of squares.
  207. 8:56In this case, the sum of squares around
  208. 8:58the mean equals 100
  209. 9:01and the sum of squares around the fit
  210. 9:03equals 40.
  211. 9:05Plugging those numbers into the equation
  212. 9:07gives us the same value we had before. R
  213. 9:10squared equals 0.6, which equals 60%.
  214. 9:1660% of the sums of squares of the mouse
  215. 9:19size can be explained by mouse weight.
  216. 9:23Here's another example. We're also going
  217. 9:25to go back to using variation in the
  218. 9:27calculation, since that's more common.
  219. 9:30In this case, knowing mouse weight means
  220. 9:33you can make a perfect prediction of
  221. 9:36mouse size.
  222. 9:38The variation around the mean is the
  223. 9:40same as it was before, 11.1.
  224. 9:44But now the variation around the fitted
  225. 9:46line equals zero because there are no
  226. 9:48residuals.
  227. 9:50Plugging the numbers in gives us an R
  228. 9:52squared equal to one, which equals 100%.
  229. 9:57In this case, mouse weight explains 100%
  230. 10:02of the variation in mouse size.
  231. 10:05Okay. One last example.
  232. 10:09In this case, knowing mouse weight
  233. 10:12doesn't help us predict mouse size.
  234. 10:15If someone tells us they have a heavy
  235. 10:17mouse, well, that mouse could either be
  236. 10:19small or large with equal probability.
  237. 10:23Similarly, if someone said they had a
  238. 10:25light mouse, well, again, we wouldn't
  239. 10:28know if it was a big mouse or a small
  240. 10:30mouse because each of those options is
  241. 10:33equally likely.
  242. 10:35Just like the other two examples, the
  243. 10:37variation around the mean is equal 11.1.
  244. 10:41However, in this case, the variation
  245. 10:43around the fit is also equal 11.1.
  246. 10:47So, we plug those numbers in and we get
  247. 10:50R squared equals zero, which equals zero
  248. 10:52percent.
  249. 10:54In this case, mouse weight doesn't
  250. 10:56explain any of the variation around the
  251. 10:59mean.
  252. 11:00When calculating the sum of squares
  253. 11:02around the mean, we collapse the points
  254. 11:05onto the Y axis just to emphasize the
  255. 11:08fact that we were ignoring mouse weight.
  256. 11:12But we could just as easily draw a line
  257. 11:15Y equals the mean mouse size
  258. 11:18and calculate the sum of squares around
  259. 11:20the mean around that.
  260. 11:24In this example, we applied R squared to
  261. 11:27a simple equation for a line Y equals
  262. 11:310.1
  263. 11:32+ 0.78
  264. 11:34* x.
  265. 11:36This gave us an r-squared of 60% meaning
  266. 11:4060% of the variation in mouse size could
  267. 11:43be explained by mouse weight.
  268. 11:46But the concept applies to any equation,
  269. 11:49no matter how complicated.
  270. 11:51First, you measure, square, and sum the
  271. 11:54distance from the data to the mean.
  272. 11:57Then measure, square, and sum the
  273. 12:00distance from the data to the
  274. 12:02complicated equation.
  275. 12:04Once you've got those two sums of
  276. 12:05squares, just plug them in and you've
  277. 12:07got r-squared.
  278. 12:10Let's look at a slightly more
  279. 12:11complicated example.
  280. 12:14Imagine we wanted to know if mouse
  281. 12:17weight and tail length did a good job
  282. 12:19predicting the length of the mouse's
  283. 12:21body.
  284. 12:23So we measure a bunch of mice.
  285. 12:26To plot this data, we need a
  286. 12:28three-dimensional graph.
  287. 12:31We want to know how well weight and tail
  288. 12:34length
  289. 12:35predict body length.
  290. 12:37The first mouse we measured had weight =
  291. 12:402.1,
  292. 12:42tail length = 1.3,
  293. 12:45and body length = 2.5.
  294. 12:49So that's how we plot this data on this
  295. 12:513D graph.
  296. 12:53Here's all the data in the graph.
  297. 12:56The larger circles are points that are
  298. 12:58closer to us and represent mice that
  299. 13:01have shorter tails.
  300. 13:03The smaller circles are points that are
  301. 13:05further from us and represent mice with
  302. 13:08longer tails.
  303. 13:10Now we do a least squares fit.
  304. 13:13Since we have the extra term in the
  305. 13:15equation representing an extra
  306. 13:17dimension, we fit a plane instead of a
  307. 13:20line.
  308. 13:22Here's the equation for the plane.
  309. 13:25The y value represents body length.
  310. 13:29Least squares estimates three different
  311. 13:32parameters.
  312. 13:34The first is the Y intercept. That's
  313. 13:37when both tail length and mouse weight
  314. 13:39are equal to zero.
  315. 13:41The second parameter, 0.7,
  316. 13:44is for the mouse weight.
  317. 13:47The last term,
  318. 13:480.5,
  319. 13:50is for the tail length.
  320. 13:52If we know a mouse's weight and tail
  321. 13:55length, we can use the equation to guess
  322. 13:58the body length.
  323. 14:00For example, given the weight and tail
  324. 14:02length for this mouse,
  325. 14:05the equation predicts this body length.
  326. 14:09Just like before, we can measure the
  327. 14:11residuals, square them, and then add
  328. 14:13them up to calculate R squared.
  329. 14:17Now,
  330. 14:18if the tail length, or the Z axis, is
  331. 14:21useless and doesn't make the sum of
  332. 14:23squares fit any smaller, then least
  333. 14:26squares will ignore it by making that
  334. 14:28parameter equal to zero.
  335. 14:31In this case, plugging the tail length
  336. 14:33into the equation would have no effect
  337. 14:36on predicting the mouse size.
  338. 14:39This means equations with more
  339. 14:41parameters will never make the sum of
  340. 14:44squares around the fit worse than
  341. 14:46equations with fewer parameters.
  342. 14:49In other words,
  343. 14:50this equation,
  344. 14:52mouse size = 0.3
  345. 14:55+ mouse weight + flip of a coin +
  346. 14:59favorite color + astrological sign +
  347. 15:02extra stuff, will never perform worse
  348. 15:05than this equation,
  349. 15:07mouse size = 0.3 + mouse weight.
  350. 15:11This is because least squares will cause
  351. 15:13any term that makes sum of squares
  352. 15:15around the fit worse to be multiplied by
  353. 15:18zero, and in a sense, no longer exist.
  354. 15:23Now, due to random chance, there is a
  355. 15:26small probability that the small mice in
  356. 15:29the data set might get heads more
  357. 15:31frequently than large mice.
  358. 15:34If this happened, then we'd get a
  359. 15:36smaller sum of squares fit
  360. 15:38and a better R squared.
  361. 15:41Womp womp. Here's the frowny face of sad
  362. 15:45times.
  363. 15:47The more silly parameters we add to the
  364. 15:49equation, the more opportunities we have
  365. 15:52for random events to reduce sum of
  366. 15:55squares fit and result in a better R
  367. 15:57squared.
  368. 15:59Thus, people report an adjusted R
  369. 16:01squared value that, in essence, scales R
  370. 16:05squared by the number of parameters.
  371. 16:09R squared is awesome,
  372. 16:11but it's missing something.
  373. 16:13What if all we had were two
  374. 16:15measurements?
  375. 16:17We'd calculate the sum of squares around
  376. 16:19the mean. In this case, that would be
  377. 16:2110.
  378. 16:23Then we'd calculate the sum of squares
  379. 16:25around the fit,
  380. 16:26which equals zero.
  381. 16:29The sum of squares around the fit equals
  382. 16:31zero because you can always draw a
  383. 16:33straight line to connect any two points.
  384. 16:37What this means is when we calculate R
  385. 16:40squared by plugging the numbers in,
  386. 16:42we're going to get 100%.
  387. 16:45100% is a great number. We've explained
  388. 16:48all the variation, but any two random
  389. 16:51points will give us the exact same
  390. 16:53thing. It doesn't actually mean
  391. 16:55anything.
  392. 16:57We need a way to determine if the R
  393. 17:00squared value is statistically
  394. 17:02significant.
  395. 17:04We need a P value.
  396. 17:06Before we calculate the P value, let's
  397. 17:09review the main concepts behind R
  398. 17:11squared one last time.
  399. 17:14The general equation for R squared is
  400. 17:17the variance around the mean minus the
  401. 17:19variance around the fit divided by the
  402. 17:22variance around the mean.
  403. 17:24In our example, this means the variation
  404. 17:27in the mouse size minus the variation
  405. 17:30after taking weight into account divided
  406. 17:33by the variation in mouse size.
  407. 17:36In other words, r squared equals the
  408. 17:38variation in mouse size explained by
  409. 17:41weight divided by the variation in mouse
  410. 17:44size without taking weight into account.
  411. 17:48In this particular example, r squared
  412. 17:51equals 0.6,
  413. 17:53meaning we saw a 60% reduction in
  414. 17:55variation once we took mouse weight into
  415. 17:58account.
  416. 18:00Now that we have a thorough
  417. 18:01understanding of the ideas behind r
  418. 18:04squared, let's talk about the main ideas
  419. 18:07behind calculating a p value for it.
  420. 18:10The p value for r squared comes from
  421. 18:13something called f.
  422. 18:16F is equal to the variation in mouse
  423. 18:19size explained by weight divided by the
  424. 18:22variation mouse size not explained by
  425. 18:25weight.
  426. 18:27The numerators for r squared and for f
  427. 18:31are the same.
  428. 18:33That is to say, it's the reduction in
  429. 18:35variance when we take the weight into
  430. 18:37account.
  431. 18:39The denominator is a little different.
  432. 18:42These dotted lines, the residuals,
  433. 18:45represent the variation that remains
  434. 18:48after fitting the line.
  435. 18:50This is the variation that is not
  436. 18:52explained by weight.
  437. 18:54So together,
  438. 18:55we have the variation in mouse size
  439. 18:57explained by weight divided by the
  440. 19:00variation in mouse size not explained by
  441. 19:03weight.
  442. 19:05Now let's look at the underlying
  443. 19:07mathematics.
  444. 19:08Just as a reminder, here's the equation
  445. 19:11for R squared.
  446. 19:13This is the general equation that will
  447. 19:16tell us if R squared is significant.
  448. 19:19The meat of these two equations are very
  449. 19:22similar and rely on the same sums of
  450. 19:24squares.
  451. 19:26Like we said before, the numerators are
  452. 19:29the same.
  453. 19:30In our mouse size and weight example,
  454. 19:33the numerator is the variation in mouse
  455. 19:36size explained by weight.
  456. 19:39And the sum of squares around the fit is
  457. 19:41just the residuals squared and summed up
  458. 19:45around the fitted line. So, that's the
  459. 19:47variation that the fit does not explain.
  460. 19:51These numbers over here are the degrees
  461. 19:53of freedom.
  462. 19:55They turn the sums of squares into
  463. 19:57variances.
  464. 19:59I'm going to dedicate a whole StatQuest
  465. 20:02to degrees of freedom, but for now,
  466. 20:05let's see if we can get an intuitive
  467. 20:06feel for what they're doing here.
  468. 20:10Let's start with these.
  469. 20:13P fit is the number of parameters in the
  470. 20:16fit line.
  471. 20:17Here's the equation for the fit line in
  472. 20:20a general format. We just have the Y
  473. 20:22intercept plus the slope times X.
  474. 20:26The Y intercept and the slope are two
  475. 20:29separate parameters.
  476. 20:31That means P fit equals two.
  477. 20:35P mean is the number of parameters in
  478. 20:38the mean line.
  479. 20:40In general, that equation is Y equals
  480. 20:43the Y intercept. That's what gives us a
  481. 20:46horizontal line that cuts through the
  482. 20:48data.
  483. 20:49In this case, the Y intercept is the
  484. 20:52mean value.
  485. 20:54This equation just has one parameter.
  486. 20:58Thus, P mean equals one.
  487. 21:02Both equations have a parameter for the
  488. 21:04Y intercept.
  489. 21:07However, the fit line has one extra
  490. 21:10parameter, the slope.
  491. 21:12In our example,
  492. 21:13this slope is the relationship between
  493. 21:16weight and size.
  494. 21:19In this example,
  495. 21:20P fit minus P mean equals two minus one,
  496. 21:25which equals one.
  497. 21:27The fit has one extra parameter, mouse
  498. 21:30weight.
  499. 21:32Thus,
  500. 21:33the numerator is the variance explained
  501. 21:36by the extra parameter.
  502. 21:38In our example, that's the variance in
  503. 21:40mouse size explained by mouse weight.
  504. 21:44If we had used mouse weight and tail
  505. 21:47length to explain variation in size,
  506. 21:50then we would end up with an equation
  507. 21:52that had three parameters and P fit
  508. 21:55would equal three.
  509. 21:57Thus, P fit minus P mean would equal
  510. 22:01three minus one, which equals two.
  511. 22:04Now, the fit has two extra parameters,
  512. 22:07mouse weight and tail length.
  513. 22:11With the fancier equation for the fit,
  514. 22:14the numerator is the variance in mouse
  515. 22:16size explained by mouse weight and tail
  516. 22:19length.
  517. 22:21Now, let's talk about the denominator
  518. 22:23for our equation for F.
  519. 22:26The denominator is the variation in
  520. 22:29mouse size not explained by the fit.
  521. 22:33That is to say,
  522. 22:35it's the sum of squares of the residuals
  523. 22:37that remain after we fit our new line to
  524. 22:40the data.
  525. 22:42Why divide sum of squares fit by N minus
  526. 22:46P fit instead of just N?
  527. 22:50Intuitively,
  528. 22:51the more parameters you have in your
  529. 22:53equation,
  530. 22:54the more data you need to estimate them.
  531. 22:57For example, you only need two points to
  532. 23:00estimate a line,
  533. 23:01but you need three points to estimate a
  534. 23:03plane.
  535. 23:05If the fit is good,
  536. 23:07then the variation explained by the
  537. 23:09extra parameters in the fit will be a
  538. 23:11large number, and the variation not
  539. 23:14explained by the extra parameters in the
  540. 23:16fit will be a small number.
  541. 23:18That makes F a really large number.
  542. 23:22Now, that question we've all been dying
  543. 23:24to know the answer to,
  544. 23:26how do we turn this number into a P
  545. 23:28value?
  546. 23:30Conceptually,
  547. 23:31generate a set of random data.
  548. 23:34Calculate the mean and the sum of
  549. 23:36squares around the mean.
  550. 23:39Calculate the fit and the sum of squares
  551. 23:41around the fit.
  552. 23:44Now, plug all those values into our
  553. 23:46equation for F,
  554. 23:48and that will give us a number. In this
  555. 23:50case, that number is two.
  556. 23:52Now, plot that number in a histogram.
  557. 23:56Now, generate another set of random
  558. 23:58data.
  559. 23:59Calculate the mean and the sum of
  560. 24:01squares around the mean.
  561. 24:03Then calculate the fit and the sum of
  562. 24:06squares around the fit.
  563. 24:08Plug those values into our equation for
  564. 24:10F,
  565. 24:12and in this case, we get F equals three.
  566. 24:15So, we then plug that value into our
  567. 24:17histogram.
  568. 24:19And then we repeat with yet another set
  569. 24:22of random data.
  570. 24:23In this case, we got F equals one.
  571. 24:26That's plotted on our histogram.
  572. 24:28And we just keep generating more and
  573. 24:30more random data sets, calculating the
  574. 24:33sums of squares, plugging them into our
  575. 24:35equation for F, and plotting the results
  576. 24:38on our histogram.
  577. 24:40Now, imagine we did that hundreds, if
  578. 24:43not millions, of times.
  579. 24:46When we're all done with our random data
  580. 24:47sets, we return to our original data
  581. 24:50set.
  582. 24:52We then plug the numbers into our
  583. 24:54equation for F. In this case, we got F =
  584. 24:576.
  585. 24:59The P value is the number of more
  586. 25:02extreme values divided by all of the
  587. 25:05values.
  588. 25:06So, in this case, we have the value at F
  589. 25:09= 6 and the value at F = 7 divided by
  590. 25:13all the other randomizations that we
  591. 25:15created originally.
  592. 25:17If this concept is confusing to you, I
  593. 25:20have a StatQuest that explains P values,
  594. 25:22so check that one out.
  595. 25:25Bam!
  596. 25:27You can approximate the histogram with a
  597. 25:29line.
  598. 25:30In practice, rather than generating tons
  599. 25:33of random data sets, people use the line
  600. 25:35to calculate the P value.
  601. 25:38Here's an example of a one standard F
  602. 25:41distribution that people use to
  603. 25:43calculate P values.
  604. 25:45The degrees of freedom determine the
  605. 25:47shape.
  606. 25:49The red line represents another standard
  607. 25:52F distribution that people use to
  608. 25:54calculate P values.
  609. 25:56In this case, the sample size used to
  610. 25:59draw the red line is smaller than the
  611. 26:01sample size used to draw the blue line.
  612. 26:05Notice that when N minus P fit equals
  613. 26:0810, the distribution tapers off faster.
  614. 26:13This means that the P value will be
  615. 26:16smaller when there are more samples
  616. 26:18relative to the number of parameters in
  617. 26:20the fit equation.
  618. 26:22Triple bam!
  619. 26:24Hooray! We finally got our P value. Now,
  620. 26:27let's review the main ideas.
  621. 26:31Given some data that you think are
  622. 26:32related,
  623. 26:34linear regression quantifies the
  624. 26:37relationship in the data.
  625. 26:39This is R squared.
  626. 26:41This needs to be large.
  627. 26:44It also determines how reliable that
  628. 26:46relationship is.
  629. 26:48This is the P value that we calculated
  630. 26:50with F.
  631. 26:51This needs be small.
  632. 26:53You need both to have an interesting
  633. 26:55result.
  634. 26:57Hooray! We've made it to the end of
  635. 27:00another exciting StatQuest. Wow, this
  636. 27:03was a long one.
  637. 27:04I hope you had a good time.
  638. 27:06If you like this and want to see more
  639. 27:08StatQuests like it, why don't you
  640. 27:10subscribe to my channel? It's real easy,
  641. 27:12just click the red button.
  642. 27:14And if you have any ideas of StatQuests
  643. 27:17that you'd like me to create, just put
  644. 27:19them in the comments below. That's all
  645. 27:21there is to it. All right. Tune in next
  646. 27:23time for another really exciting
  647. 27:25StatQuest.

About this transcript

This page contains the full transcript of Linear Regression, Clearly Explained!!! by StatQuest with Josh Starmer, generated from the public captions YouTube serves with the video. The transcript has 3,687 words across 647 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.