BTW, the error message my program gives me for the B and M functions is:<br><br><div style="margin-left: 40px; color: rgb(51, 204, 255);"><span style="color: rgb(0, 0, 153);">Traceback (most recent call last):</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">  File &quot;I:\Lab 7 wierd stat data.py&quot;, line 49, in &lt;module&gt;</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">    B()</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">  File &quot;I:\Lab 7 wierd stat data.py&quot;, line 44, in B</span><br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">    ((Y() * Q()) - (P() * X())) / ((6 * Q()) - (X()**2))</span><br style="color: rgb(0, 0, 153);">
<span style="color: rgb(0, 0, 153);">TypeError: unsupported operand type(s) for *: &#39;NoneType&#39; and &#39;NoneType&#39;</span><br></div><br><div class="gmail_quote">On Thu, Oct 14, 2010 at 11:09 PM, Colleen Glaeser <span dir="ltr">&lt;<a href="mailto:songbird42371@gmail.com">songbird42371@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Dear tutors,<br><br>I am in a beginning-level computer science class in college and am running into problems with an assignment.<br>
<br>The assignment is as follows:<br><br><p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">
Statisticians are fond of drawing regression lines.<span>  </span>In statistics and other fields where people
analyze lots of data, one of the most commonly used regression lines is called
the “least squares line.” This is the line that is supposed to best fit the set
of data points, in the sense that it minimizes the squared vertical distances
between the points and the line.<span>  </span>Why
this should be a good fit is beyond the scope of this assignment.</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Presume that you have a collection of n two-dimensional data
points.<span>  </span>I’ll give it as a list of lists,
where each of the lists inside represents one data point.</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><span>Data :[</span> [x<sub>1</sub>, y<sub>1</sub>],
[x<sub>2</sub>, y<sub>2</sub>], [x<sub>3</sub>, y<sub>3</sub>], …, [<span>x<sub>n</sub></span>, <span>y<sub>n</sub></span>]]</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Compute the following</p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image002.gif" height="46" width="69"></p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image004.gif" height="46" width="63"></p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image006.gif" height="46" width="77"></p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image008.gif" height="51" width="89"></p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">The regression line is then given by </p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image010.gif" height="18" width="79"></p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><span>where</span> m and b may be obtained by</p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image012.gif" height="36" width="84"></p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><span>and</span></p>

<p class="MsoNormal" style="text-align: center; margin-left: 40px; color: rgb(255, 0, 0);" align="center"><img src="http://www2.truman.edu/%7Ejneitzke/cs170f10/Lab%207_files/image014.gif" height="36" width="97"></p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Your task is to compute the m and b (slope and intercept,
respectively) for a set of data.<span>  </span>You have
to analyze the data as given, not count or add anything yourself.<span>  </span>Your program should do everything, even
figure out how many data points there are.</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Here’s your data:</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">First set:<span>  </span><span>[ [</span>3, 1], [4, 3], [6, 4], [7, 6], [8, 8], [9, 8] ]</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Second set:<span>  </span><span>[ [</span>63, 11], [22, 7.5], [63, 11], [28, 10], [151, 12], [108,
10], [18, 8], [115, 10], [31,7], [44, 9] ]</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Find m and b, then calculate an estimate for x = 5 using the
first data set.<span>  </span>That is, plug in 5 for x
and see what y you get.<span>  </span>For the second
set, try x = 95.</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Turn in:<span>  </span>code, m, b,
and the estimates for both data sets. </p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"> </p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">***********************************************************************************************************************</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">There’s an easy way to walk through the data and extract the
values you need.<span>  </span>Use <span>a
for</span> loop.<span>  </span>Try this:</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><span><span style="font-family: &quot;Courier New&quot;;">for</span></span><span style="font-family: &quot;Courier New&quot;;"> item in data:</span></p>



<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;"><span>    </span>[<span>x</span>, y] = item</span></p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;"><span>    </span><span>print(</span>x)</span></p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>

<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">For extra credit:<span> 
</span>draw a scatter plot of the data, and draw in the least squares
line.<span>  </span>Scale the window to fit, making it
a bit wider and higher than the data requires, so that some of the points are
near but not on the edges of the window.<span> 
</span>Then sketch in the regression line.<span> 
</span>Note that you should calculate the window size based on the data – don’t
set them yourself; find the max and min values for x and y.<span>  </span>You can print the scatter plot, or point me
toward your web page.<span>  </span>In any case, show
me the code.</p><p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><br></p><br>So far, my program is as follows:  <br><br><div style="margin-left: 40px; color: rgb(51, 204, 0);">Data = [[3,1],[4,3],[6, 4],[7, 6],[8, 8],[9, 8]]<br>

<br>def X():<br>    accX = 0 <br>    for item in Data:<br>        [x,y] = item<br><br>        accX = accX + x<br>    print (accX)<br><br><br>def Y():<br>    accY = 0 <br>    for item in Data:<br>        [x,y] = item<br><br>

        accY = accY + y<br>    print (accY)<br><br>def P():<br>    accXY = 0 <br>    for item in Data:<br>        [x,y] = item<br><br>        accXY = accXY + (y*x)<br>    print (accXY)<br><br>def Q():<br>    accX2 = 0 <br>

    for item in Data:<br>        [x,y] = item<br><br>        accX2 = accX2 + (x**2)<br>    print (accX2)<br><br>X()<br>Y()<br>P()    <br>Q()<br><br><br><br>def B():<br>    ((Y() * Q()) - (P() * X())) / ((6 * Q()) - (X()**2))<br>

<br>def M():<br>    ((Y() * Q()) - (P() * X())) / (X() * Q())<br><br>B()<br>M()<br></div><br>Now, my functions for X, Y, P, and Q are correct, but I have a couple of problems when it comes to continuing.  First of all, despite what my teacher has told me, my method for trying to multiply X,Y,P, and Q&#39;s results in the functions for B and M are not working.  I&#39;m not sure if there is a way to make functions into variables or how to solve this problem.  <br>

<br>Second, I am confused as to what my teacher means to do when it comes to inputting different values of x.  <br clear="all"><p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Find m and b, then calculate an estimate for x = 5 using the
first data set.<span>  </span>That is, plug in 5 for x
and see what y you get.<span>  </span>For the second
set, try x = 95.</p>


<p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal">Turn in:<span>  </span>code, m, b,
and the estimates for both data sets. <br></p><p style="margin-left: 40px; color: rgb(255, 0, 0);" class="MsoNormal"><br></p>I mean, I know I need to calculate the line of best fit for the data sets using B and M, but what in the world is x supposed to do and where does it go?  How do I program this?  This is especially harder since I&#39;ve never taken a proper stat class before.  <br>

<br>Thank you all so much! <br><font color="#888888"><br>-- <br>Colleen Glaeser<br><a href="mailto:songbird42371@gmail.com" target="_blank">songbird42371@gmail.com</a> <br>636.357.8519<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Colleen Glaeser<br><a href="mailto:songbird42371@gmail.com">songbird42371@gmail.com</a> <br>636.357.8519<br>