;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variable declarations ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; globals [ shape-names ;; list that holds the names of the shapes a student's turtle can have m ;; the slope of the line of regression- only calculated if linear-regression? is true b ;; the y-intersept of the line of regression- only calculated if linear-regression? is true r-square ;; the correlation coefficient of the line of regression- only calculated if linear-regression? is true equation ;; the equation for the line of regression- only calculated if linear-regression? is true challenge ;; holds the current verbal challenge that the instructor gives to the users ;; quick start instructions variables quick-start ;; the current quickstart instruction displayed in the quickstart monitor qs-item ;; the index of the current quickstart instruction qs-items ;; the list of quickstart instructions ] turtles-own [ user-id ;; unique id generated by each calculator to identify each student or teacher turtle ] patches-own [ axis? ;; true if the pxcor or pycor are 0 reg-point? ;; true if the patch falls on the line of regression ] ;;;;;;;;;;;;;;;;;;;;; ;; Setup Functions ;; ;;;;;;;;;;;;;;;;;;;;; to startup setup-quick-start hubnet-set-client-interface "TI-83+" [ "AAA - Function Activity 2.4" [ "L1" ] ] hubnet-reset setup end ;; Initializes the display, and creates a list that contains the names of the shapes ;; used by turtles in this activity. The placement of the shape names in the last ;; corresponds to the numbers sent by calculators. to setup cc cp ct clear-all-plots ;; setup and draw the axes ask patches [ ifelse (pxcor = 0 or pycor = 0) [ set pcolor 2 set axis? true ] [ set pcolor 0 set axis? false ] ] ;; create a list of the shape names for the calculators to use set shape-names ["wide wedge" "square" "" "thin wedge" "" "" "" "car"] ;; initialize the equation for the line of regression to be nothing set equation "" ;; initially set the challenge to nothing set challenge "" ;; send the appropriate setup information to the calculators setup-hubnet end ;; give the user some information about what the setup button does so they can ;; know whether they want to proceed before actually doing the setup to setup-prompt if user-yes-or-no? ("The SETUP button should only be used when starting " + "over with a new group (such as a new set of students) since " + "all data is lost. Use the RE-RUN button for continuing with " + "an existing group." + "\n\nDo you really want to setup the model?") [ user-message "Before closing this dialog, please do the following:" + "\n -Have everyone that is currently logged in, log off and " + "clear the calulator memory. (Press 2nd MEM 7 1 2)" + "\n -Open the teacher console for this activity and press the ERASE ALL DATA button." setup ] end ;; only used in testing- creates some turtles to test the activity to make-test-turtles [ num ] cct num [ set heading 0 setxy random-float screen-size-x random-float screen-size-y set user-id -1 ] end ;;;;;;;;;;;;;;;;;;;;;;; ;; Runtime Functions ;; ;;;;;;;;;;;;;;;;;;;;;;; ;; receives information from the calculators and runs the simulation to go ;; set all patches to have be not patches on the line of regression ask patches [ set reg-point? false ] ;; get any new information from the calculators listen-calc ;; do the calculations for determining the equation of the line of regression and correlation coefficient if linear-regression? [ lin-reg ] ;; remove or draw the line of regression for all patches that have reg-point? true ask patches [ ;; draw the line of regression. note: reg-point? can only ever be true if linear-regression? is true ifelse reg-point? [ set pcolor 13 ] [ ;; draw the axes or the background to an appropriate color ifelse axis? [ set pcolor 2 ] [ set pcolor black ] ] ] end to lin-reg locals [ ave-x ;; the average of all the turtles' xcors ave-y ;; the average of all the turtles' ycors sum-x ;; the sum of all the turtles' xcors sum-y ;; the sum of all the turtles' ycors sum-xy ;; the sum of the product of each turtle's xcor and ycor sum-x-square ;; the sum of the product of each turtle's xcor squared sum-y-square ;; the sum of the product of each turtle's ycor squared num-turtles ;; the number of turtles denominator ;; holds the denominator for the calculations of the slope and the y-intersept xcors ;; a list containing the xcors of the turtles ycors ;; a list containing the ycors of the turtles ] ;; you need to have at least two points to make a line if count patches with [ any? turtles-here ] > 1 [ ;; initialize the variables set num-turtles count turtles set xcors values-from turtles [ xcor ] set ycors values-from turtles [ ycor ] set sum-x sum xcors set sum-y sum ycors set ave-x sum-x / num-turtles set ave-y sum-y / num-turtles set sum-xy sum values-from turtles [ xcor * ycor ] set sum-x-square sum values-from turtles [ xcor * xcor ] set sum-y-square sum values-from turtles [ ycor * ycor ] ;; compute and store the demonimator for the slope and y-intercept so we don't have to do it twice set denominator ( sum-x-square - num-turtles * ( ave-x ^ 2 ) ) ;; if the denominator = 0 or the min of xcors = the max of xcors, the turtles are in a vertical line ;; thus, the line of regression will be undefined and have a r^2 value of 1.0 ifelse ( denominator = 0 ) or ( min xcors = max xcors ) [ set m 0 set b 0 set equation "Undefined" ;; since all the turtles are in a line r^2 must be 1 set r-square 1 ;; set all the patches in the column to be on the line ask patches with [ pxcor = xcor-of one-of turtles ] [ set reg-point? true ] ] [ ;; otherwise, we have some other type of line. so find the y-intersept and slope of the line set b ( ( ave-y * sum-x-square ) - ( ave-x * sum-xy ) ) / denominator set m ( sum-xy - num-turtles * ave-x * ave-y ) / denominator ;; set the equation to the appropriate string set equation ( precision m 2 ) + "X + " + ( precision b 2 ) ;; compute the value of r^2 ifelse ( ( sum-y-square - num-turtles * ( ave-y ^ 2 ) ) = 0 ) or ( min ycors = max ycors ) [ set r-square 1 ] [ set r-square ( ( sum-xy - num-turtles * ave-x * ave-y ) ^ 2 ) / ( ( sum-x-square - num-turtles * ( ave-x ^ 2 ) ) * ( sum-y-square - num-turtles * ( ave-y ^ 2 ) ) ) ] ;; set the patches' reg-point? to true if they lie on the line of regression ask patches with [ pycor = round ( m * pxcor + b ) ] [ set reg-point? true ] ] ] end ;; sets challenge to the value that the user enters in an input dialog to set-challenge set challenge user-input "Enter the Verbal Challenge:" end ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Quick Start functions ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; initialize instructions to quickly setup the model, calculators, and TISchool webpage to run this activity to setup-quick-start set qs-item 0 set qs-items [ "Teacher: Follow these directions to setup the HubNet activity." "Optional- Zoom In (see Tools in the Menu Bar) - optional" "Press the GO button." "Everyone: Reset the RAM on your calculator (2nd MEM 7 1 2)." "Login to the calculator." "Choose the PICK POINTS option." "Remember your shape and color and press ENTER." "Move around using the arrow keys to..." "acquaint yourselves with the interface." "Teacher: Issue your students a challenge, such as..." "create a mock data set with an R^2 of .75." "Optional- Press the NetLogo SET CHALLENGE button and enter..." "the challenge to be displayed in the CURRENT CHALLENGE monitor." "Teacher: To rerun the activity, do not clear the server." "Stop the simulation by pressing the NetLogo GO button." "Press the NetLogo RE-RUN button." "Press the GO button." "Everyone: Exit to the calculator Main Menu." "Choose the RESTART option from the calculator Main Menu." "Choose the PICK POINTS option and continue." "Teacher: To start the simulation over with a new group,..." "stop the model by pressing the NetLogo GO button, if it is on." "Have everyone, including yourself, logout of their calculators." "Press the ERASE ALL DATA button on the TISCHOOL site." "Press the NetLogo SETUP button." "Follow these instructions from the beginning again." ] set quick-start item qs-item qs-items end ;; view the next item in the quickstart monitor to view-next set qs-item qs-item + 1 if qs-item >= length qs-items [ set qs-item length qs-items - 1 ] set quick-start item qs-item qs-items end ;; view the previous item in the quickstart monitor to view-prev set qs-item qs-item - 1 if qs-item < 0 [ set qs-item 0 ] set quick-start item qs-item qs-items end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Code for interacting with the calculators ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; send the appropriate setup information to the calculators to setup-hubnet locals [ parameters ;; the setup information to be sent to the calculators ] set parameters [ 1 ] ;; 1 means that we can only have one point on the calculators set parameters lput (- screen-edge-x) parameters ;; append the negative screen-edge-x set parameters lput screen-edge-x parameters ;; append the screen-edge-x set parameters lput (- screen-edge-y) parameters ;; append the negative screen-edge-y set parameters lput screen-edge-y parameters ;; append the screen-edge-y hubnet-broadcast "PARAM" parameters end ;; when a command is sent, this finds out which calculator sent it and then executes the command to listen-calc locals [ current-id cmd ] while [ hubnet-message-waiting? ] [ hubnet-fetch-message set current-id hubnet-message-source set cmd item 0 hubnet-message execute-cmd current-id cmd ] end to execute-cmd [ current-id cmd ] if cmd = 0 [ exe-crt current-id ] if cmd = 3 [ exe-kill current-id ] end ; 0 Create or Move current Turtles - receives a list 6 items long - 1, shape, color, x, y, and point number (this is unused) to exe-crt [ current-id ] ifelse not any? turtles with [ user-id = current-id ] [ cct item 1 hubnet-message [ set user-id current-id set heading 0 set shape item (item 2 hubnet-message) shape-names set color (item 3 hubnet-message) setxy (item 4 hubnet-message) (item 5 hubnet-message) ] ] [ ask turtles with [ user-id = current-id ] [ setxy (item 4 hubnet-message) (item 5 hubnet-message) ] ] end ;3 Kill Turtles - kills turtle associated with id current-id to exe-kill [ current-id ] ask turtles with [ user-id = current-id ] [ die ] end ; ***NetLogo Model Copyright Notice*** ; This activity and associated models and materials was created as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS. ; The project gratefully acknowledges the support of the ; National Science Foundation ( REPP program ) -- grant number REC #9814682. ; Copyright 2000 by Uri Wilensky & Walter Stroup. Updated 2001,2002. All rights reserved. ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from the copyright holders. ; Contact the copyright holders for appropriate licenses for redistribution for ; profit. ; To refer to this model in academic publications, please use: ; Wilensky, U. & Stroup, W. (2000). NetLogo HubNet Regression model. ; http://ccl.northwestern.edu/netlogo/models/HubNetRegression. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; In other publications, please use: ; Copyright 1998 by Uri Wilensky and Walter Stroup. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/HubNetRegression ; for terms of use. ; ; ***NetLogo Model Copyright Notice*** @#$#@#$#@ GRAPHICS-WINDOW 179 148 706 520 23 15 11.0 1 12 1 1 1 CC-WINDOW 4 522 345 640 Command Center BUTTON 3 10 68 43 Setup setup-prompt NIL 1 T OBSERVER T BUTTON 170 60 235 93 Go go T 1 T OBSERVER T MONITOR 2 234 69 283 Mouse X (round mouse-xcor) 1 1 MONITOR 74 234 141 283 Mouse Y (round mouse-ycor) 1 1 MONITOR 243 10 695 59 Quick Start Instructions (more details in info tab) quick-start 0 1 BUTTON 461 60 539 93 <<< PREV view-prev NIL 1 T OBSERVER T BUTTON 538 60 622 93 NEXT >>> view-next NIL 1 T OBSERVER T BUTTON 259 60 406 93 Reset Instructions setup-quick-start NIL 1 T OBSERVER T MONITOR 2 179 177 228 Number of Points at Mouse count turtles-at round mouse-xcor round mouse-ycor 0 1 SWITCH 3 299 175 332 linear-regression? linear-regression? 0 1 -1000 MONITOR 2 389 52 438 R^2 r-square 2 1 MONITOR 3 337 177 386 Equation equation 3 1 MONITOR 137 96 696 145 Current Challenge challenge 3 1 BUTTON 4 102 129 135 Set Challenge set-challenge NIL 1 T OBSERVER T BUTTON 76 60 157 93 Re-Run setup NIL 1 T OBSERVER T @#$#@#$#@ WHAT IS IT? ----------- This model is used for an introductory approach to regressions. Linear Regression is the fitting of a straight line through a given set of points. Most commonly, the best-fit line is used. The best-fit line is the line that has the highest R^2 value for this set of points. R^2 is known as the correlation coefficient. This value indicates how well the line of regression fits the data on a scale from 0 to 1. The closer R^2 is to 1, the closer the line fits the data. In this model however, you will create a set of points to create a line of regression that will have a specific R^2 value. Issue your students a challenge, such as create a mock data set with an R^2 of .5 and then of .8. How did the data change? Try to data sets that have different slopes or y-intercepts. This activity requires the TI Navigator activity AAA - Function Activity 2.4 For further documentation, see the Participatory Simulations Guide found at http://ccl.northwestern.edu/ps/ HOW TO USE IT ------------- QUICKSTART INSTRUCTIONS: ------------------------ Contains instructions as to how to quickly setup the model, calculators, and TISchool web page so as to run this activity. The instructions can be found below: Teacher: Open the TISchool site in your web browser. Enable activity AAA - Function Activity 2.4. Open the teacher console and press the ERASE ALL DATA button. If it is not open already, open the NetLogo model. If you are prompted by a Login dialog, enter your teacher id and password and any other necessary information. Optional- Zoom In (see Tools in the Menu Bar) Press the GO button. Everyone: Reset the RAM on the calculator by pressing the following keys: 2nd MEM 7 1 2. Login to the calculator. Choose the PICK POINTS option. Remember your shape and color and press ENTER. Move around using the arrow keys to acquaint yourselves with the interface. Teacher: Issue your students a challenge, such as create a mock data set with an R^2 of .75. Optional- Press the NetLogo SET CHALLENGE button and enter the challenge to be displayed in the CURRENT CHALLENGE monitor. Teacher: To rerun the activity, do not clear the server. Stop the simulation by pressing the NetLogo GO button. Press the NetLogo RE-RUN button. Press the GO button. Everyone: Exit to the calculator Main Menu. Choose the RESTART option from the calculator Main Menu. Choose the PICK POINTS option and continue. Teacher: To start the simulation over with a new group, stop the model by pressing the NetLogo GO button, if it is on. Have everyone, including yourself, logout of their calculators. Press the ERASE ALL DATA button on the TISCHOOL site. Press the NetLogo SETUP button. Follow these instructions from the beginning again. BUTTONS: -------- SETUP - clears all turtles and patches. This should only be pressed when starting out with a new group of users since all data is lost. RE-RUN - sets up the model to be able to run again with the same users GO - runs the simulation SET RULE - displays an input dialog that allows the leader to enter the verbal challenge. The entered challenge is then displayed in the CURRENT CHALLENGE monitor. This is meant for a convenience of the users and has no effect on the actual running of the simulation. NEXT >>> - shows the next quick start instruction <<< PREVIOUS - shows the previous quick start instruction RESET INSTRUCTIONS - shows the first quick start instruction MONITORS: --------- MOUSE X - shows the pxcor of the patch the mouse is currently on, or if the mouse is no longer over the graphics window, it displays the pxcor of the patch the mouse was last on MOUSE Y - shows the pycor of the patch the mouse is currently on, or if the mouse is no longer over the graphics window, it displays the pycor of the patch the mouse was last on NUMBER OF POINTS AT MOUSE - shows the number of turtles on the patch the mouse is currently on, or if the mouse is no longer over the graphics window, it displays the number of turtles on the patch the mouse was last on EQUATION - shows the equation for the line of regression if LINEAR-REGRESSION? is true R^2 - shows the correlation coefficient for the line of regression if LINEAR-REGRESSION? is true CURRENT CHALLENGE- displays the last challenge that was entered when the SET CHALLENGE button was pressed. This is meant for a convenience of the users and has no effect on the actual running of the simulation. SWITCHES: --------- LINEAR-REGRESSION? - if true, the line of regression is shown. Otherwise, it is not. CALCULATOR INFORMATION ---------------------- TEACHER CALCULATOR: ------------------- Students and teacher have identical calculator programs. STUDENT CALCULATORS: -------------------- To enter the simulation, choose the PICK POINTS option. Move your point around by pressing the ARROW keys. The DONE softkey returns you to the Main Menu. The STEP softkey prompts you to change the amount of distance you move when you press an ARROW key. You can choose from 0.5, 1, and 5. THINGS TO NOTICE ---------------- What is the least number of points to create an R^2 value 0.0? 1.0? Why does it not make sense to have a regression line for only 1 data point? Is it harder to get an R^2 value of a particular value when there are more or less points? Why? What happens to the regression line and the correlation coefficient if there are multiple points on a single patch? THINGS TO TRY ------------- Challenge the students to make data sets that have correlation coefficients of different values. Move all the points the same amount in a single direction. Does the correlation coefficient change? The equation of the line of regression? Why? Find out which points have more effect on the R^2 value and the line of regression. What qualities do these points have that other points lack? Set LINEAR-REGRESSION? to OFF. Challenge the students to make a data set with a certain R^2 value or a particular equation for the regression line. Turn LINEAR-REGRESSION? ON. How accurate were they? What strategies did they use? Can they be improved? EXTENDING THE MODEL ------------------- Support having multiple data sets. Perhaps each calculator could control a particular data set. Research other types of regression and support them. CREDITS AND REFERENCES ---------------------- This activity and associated models and materials was created as part of the project: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS. The project gratefully acknowledges the support of the National Science Foundation ( REPP program ) -- grant number REC #9814682. Copyright 2000 by Uri Wilensky & Walter Stroup. Updated 2001,2002. All rights reserved. Permission to use, copy, or modify this software and its associated documentation, models and curricular materials for educational and research purposes only and without fee is hereby granted, provided that this copyright notice and the original authors' names appear on all copies and supporting documentation. For any other uses of this software, in original or modified form, including, but not limited to distribution in whole or in part, specific prior permission must be obtained from Uri Wilensky and Walter Stroup. These programs shall not be used, rewritten, or adapted as the basis of a commercial or hardware product without first obtaining appropriate licenses from Uri Wilensky & Walter Stroup. We make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. To refer to this model in academic publications, please use: Wilensky, U. & Stroup, W. (2000). NetLogo HubNet Regression model. http://ccl.northwestern.edu/netlogo/models/HubNetRegression. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 2000 by Uri Wilensky and Walter Stroup. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/HubNetRegression for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 car true 15 Circle -1 false true 185 55 60 Circle -1 false true 183 186 61 Polygon -1 true true 214 52 214 22 182 26 162 38 144 74 138 102 100 120 99 161 102 201 118 246 152 267 190 275 210 251 187 240 178 200 204 182 215 181 214 118 193 112 182 98 181 72 198 52 square true 0 Rectangle -7566196 true true 48 27 253 222 thin wedge true 0 Polygon -7566196 true true 133 20 70 252 127 148 177 245 wide wedge true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@