Y = -0.7X + 90 is the regression equation that expresses the linear relationship between:

A dependent variable (DV): LifeExpF (Life Expectancy Females)

An independent variable (IV): BirthRate (Birth Rate)

The data comes from 15 different countries. Is there a relationship between a countries Birth Rate and the average Female Life Expectancy in that country?

VIP: The 15 countries Excel spreadsheet data screen snapshot.

The SPSS statistical output results showing the relationship between the two variables: scatter plot and regression equation and the descriptive statistics for each variable. The Regression Equation is the MODEL that will be simulated.


 

powered by NetLogo

view/download model file: countries15model.nlogo

WHAT IS IT?

A linear relationship between two variables x and y is expressed as the equation for a line with slope m and intercept b.

     y = mx + b    
     
     lifeExpF = -0.7birthRate + 90
     
     m = -0.7 = slope
     b = 90 = intercept


HOW IT WORKS

Try out the different combinations of SWITCHES on the left side of the user interface. You will count only FOURTEEN scatterplot points on the SPSS scatterplot chart. You will see only FOURTEEN STARS on the above output of show15countries.

With the right combination of the Airplanes switch and the randomPlaneDirection switch settings, you will be able to discover where two countries had exactly the same (birthRate, lifeExpF) or (x, y) settings. Thus the two turtle have the same (xcor, ycor).


HOW TO USE IT

simulateRegressionModel button and the right side user interface Sliders and Switches can be used to explore the simulation model.

Be sure to also try out the instructions where you leave clearAll switch OFF. You will keep getting more and more and more cows.


THINGS TO NOTICE

What happens if you set the clearAll switch to OFF, and then click the show15countries button, followed by clicking the simulateRegressionModel button?


THINGS TO TRY

What if there were no relationship whatsoever between the two variables? The birthRate of a country would not help predict the lifeExpF for a country. The independent variable birthRate would NOT be related to the dependent variable lifeExpF.

Try turning the XandYrelated switch to OFF. Study the output that you see. Whatever the xcor (birthRate) is has no influence whatsoever on the ycor (lifeExpF) of the cows. The y variable is no longer dependent upon the x variable. They are unrelated.


NETLOGO FEATURES

It uses the netlogo random-normal function.

random-normal mean stdev

where mean = the mean and stdev means the standardDeviation

Modeling Normal Distributions: Recall the 68, 95, 99.7 rule for normal distributions. 68% leaves, 95% leaves and bugs, 99.7 percent leaves and bugs and airplanes. Within 1 or within 2 or within 3 standard deviations the mean. The z-score concept.


RELATED MODELS

Modeling Normal Distribution concept with xcor of the turtle: NormalDistributionsUpTo5Breeds.html


CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.


PROCEDURES

breed [ cows cow ]
breed [ fish aFish ]

globals [ birthRate lifeExpectancyFemale x y howFar]

TO simulateRegressionModel
   
   if clearAll [ ca ]
   
   checkerBoard
   
   create-cows howManyCows
   
   ask cows
   [
       set color blue
       set shape "cow"
       
       set size 2
       
       set x random-normal 32.9 8      ;; 13.6
       
       if x > 55 or x < 10.5 [ set x random-normal 32.9 5 ]
       
       ifelse XandYrelated
       [
          set y (-0.7 * x + 90)
          set y (y + (random-normal 0 3.5))
          if y > 90 [ set y y - 4 ]
       ]
       [
          set y random-normal 67.07 9.8
          if y > 90 [ set y y - 10 ]
       ]
       
       setxy x y
   
   ]
   
   drawLine  
END

TO show15Countries
   ca
   checkerBoard
   
   cro 1
   ask turtles 
   [
     (foreach 
         [ 55  55  59  56  68  63  53  79  72  72  68  71  72  82  81 ] ;; life expectancy female Y
         [ 46  50  48  45  31  45  50  18  28  24  34  20  28  13  13 ] ;; birth rate             X
       [
          set birthRate ?2                                ;; xcor = X is birthRate 
          
          set lifeExpectancyFemale ?1                     ;; ycor = Y is lifeExectancyFemale
          
          hatch-fish 1 [ setxy birthRate lifeExpectancyFemale 
                         ifelse airplanes
                         [ set shape "airplane" set heading random-float 360 ]
                         [ set shape "star" ]
                         set size 2 
                         set color black 
                       ]  
          
                                                    ;; Visually examine relationship between X and Y where
       ] )                                              ;;    Y = -0.7X + 90 is the equation that SPSS
   ]                                                    ;;    statistical software developed as a linear
                                                        ;;    model of the relationship.         
END

TO drawLine
   ask turtles
   [
     if who = 0
     [
       set color blue
       set pen-size 3
       
       setxy 0 90
       
       set x max-pxcor
       set y -0.7 * x + 90
       pd
       
       facexy x y
       
       set howFar distancexy x y
       fd howFar
       ht
     ]
   ]
END

TO checkerBoard
   ask patches
   [
     ifelse remainder (pxcor + pycor) 2 = 0 [ set pcolor white ] [ set pcolor 28 ]
   ]
END