Regression_Model.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ---
  2. redirect_from:
  3. - "/chapters/16/1/regression-model"
  4. interact_link: content/chapters/16/1/Regression_Model.ipynb
  5. kernel_name: python3
  6. has_widgets: false
  7. title: |-
  8. A Regression Model
  9. prev_page:
  10. url: /chapters/16/Inference_for_Regression.html
  11. title: |-
  12. Inference for Regression
  13. next_page:
  14. url: /chapters/16/2/Inference_for_the_True_Slope.html
  15. title: |-
  16. Inference for the True Slope
  17. comment: "***PROGRAMMATICALLY GENERATED, DO NOT EDIT. SEE ORIGINAL FILES IN /content***"
  18. ---
  19. <div class="jb_cell tag_remove_input">
  20. <div class="cell border-box-sizing code_cell rendered">
  21. </div>
  22. </div>
  23. <div class="jb_cell tag_remove_input">
  24. <div class="cell border-box-sizing code_cell rendered">
  25. </div>
  26. </div>
  27. <div class="jb_cell">
  28. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  29. <div class="text_cell_render border-box-sizing rendered_html">
  30. <h3 id="A-Regression-Model">A Regression Model<a class="anchor-link" href="#A-Regression-Model"> </a></h3><p>In brief, such models say that the underlying relation between the two variables is perfectly linear; this straight line is the <em>signal</em> that we would like to identify. However, we are not able to see the line clearly. What we see are points that are scattered around the line. In each of the points, the signal has been contaminated by <em>random noise</em>. Our inferential goal, therefore, is to separate the signal from the noise.</p>
  31. <p>In greater detail, the regression model specifies that the points in the scatter plot are generated at random as follows.</p>
  32. <ul>
  33. <li>The relation between $x$ and $y$ is perfectly linear. We cannot see this "true line" but it exists.</li>
  34. <li>The scatter plot is created by taking points on the line and pushing them off the line vertically, either above or below, as follows:<ul>
  35. <li>For each $x$, find the corresponding point on the true line (that's the signal), and then generate the noise or error.</li>
  36. <li>The errors are drawn at random with replacement from a population of errors that has a normal distribution with mean 0.</li>
  37. <li>Create a point whose horizontal coordinate is $x$ and whose vertical coordinate is "the height of the true line at $x$, plus the error".</li>
  38. </ul>
  39. </li>
  40. <li>Finally, erase the true line from the scatter, and display just the points created.</li>
  41. </ul>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="jb_cell">
  47. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  48. <div class="text_cell_render border-box-sizing rendered_html">
  49. <p>Based on this scatter plot, how should we estimate the true line? The best line that we can put through a scatter plot is the regression line. So the regression line is a natural estimate of the true line.</p>
  50. <p>The simulation below shows how close the regression line is to the true line. The first panel shows how the scatter plot is generated from the true line. The second shows the scatter plot that we see. The third shows the regression line through the plot. The fourth shows both the regression line and the true line.</p>
  51. <p>To run the simulation, call the function <code>draw_and_compare</code> with three arguments: the slope of the true line, the intercept of the true line, and the sample size.</p>
  52. <p>Run the simulation a few times, with different values for the slope and intercept of the true line, and varying sample sizes. Because all the points are generated according to the model, you will see that the regression line is a good estimate of the true line if the sample size is moderately large.</p>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="jb_cell tag_remove_input">
  58. <div class="cell border-box-sizing code_cell rendered">
  59. </div>
  60. </div>
  61. <div class="jb_cell">
  62. <div class="cell border-box-sizing code_cell rendered">
  63. <div class="input">
  64. <div class="inner_cell">
  65. <div class="input_area">
  66. <div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># The true line,</span>
  67. <span class="c1"># the points created,</span>
  68. <span class="c1"># and our estimate of the true line.</span>
  69. <span class="c1"># Arguments: true slope, true intercept, number of points</span>
  70. <span class="n">draw_and_compare</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
  71. </pre></div>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="output_wrapper">
  76. <div class="output">
  77. <div class="jb_output_wrapper }}">
  78. <div class="output_area">
  79. <div class="output_png output_subarea ">
  80. <img src="../../../images/chapters/16/1/Regression_Model_5_0.png"
  81. >
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. <div class="jb_cell">
  90. <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
  91. <div class="text_cell_render border-box-sizing rendered_html">
  92. <p>In reality, of course, we will never see the true line. What the simulation shows that if the regression model looks plausible, and if we have a large sample, then the regression line is a good approximation to the true line.</p>
  93. </div>
  94. </div>
  95. </div>
  96. </div>