Saturday, December 16, 2017

Assignment 6: Linear Regression

Part 1

Introduction: The goal of this assignment is to understand how to use regression to determine correlations between two variables. The regression statistic is similar to the correlation statistic; however, it utilizes Ordinary Least Square (OLS) to compute a line of best fit for the given data. OLS is a process where a line on a scatterplot is computed so total amount of distances from points on a trend line is minimized, giving the scatterplot the line of best fit.

In understanding regression analysis, there is generally a dependent and a independent variable. The dependent variable is based off of the independent variable--not the other way around. So for example: in analyzing rainfall, lets say there are two variables: the amount of rainfall, and distance from from the equator. In determining which variables are the dependent and independent variable, the amount of rainfall would be based off of distance from the equator, so distance from the equator would be the independent variable and amount of rainfall would be the dependent variable (it wouldn't make sense the other way around. Could distance from the equator be determined by rainfall? Probably not).

In computing the OLS, the result produces a "line of best fit" equation, or a linear equation. The linear equation is y = a + bx, where "a" is the constant (where the line crosses the y-axis), and b is the regression coefficient (the slope of the line). The slope determines how the dependent variable is impacted by the independent variable. The relationship can be either positive (when independent variable increases, dependent variable increases) or negative (when independent variable increases, dependent variable decreases).

In utilizing regression, strength also needs to be assessed. Strength is determined by a statistic called the coefficient of determination. The coefficient of determination is determined by r^2 (r is a statistic computed during regression analysis, in which one needs to square it to obtain the coefficient of determination). The coefficient of determination is between 0-1; numbers closer to 1 meaning a stronger relationship between the two variables, numbers closer to 0 meaning a weaker one.

In computing regression statistics, there is also a statistic called the residual. The residual determines the distance between the actual point on the scatterplot, and the line of best fit. The residual computes the distance for each point, and the sum of the standard deviation for each residual is called the standard error of the estimate. In analyzing the standard error of the estimate, the smaller the number, the more accurate the prediction.

For the first problem, we were given an excel sheet that displayed percent of kids that get free lunch in certain areas, and the crime rate per 100,000 people. The research question for the given data, is does the crime rate increase as the number of kids who obtain free lunch increase.

Methods: In determining whether or not the crime rate increases as the number of kids who obtain free lunch increases, the program SPSS was utilized to run a linear regression analysis. In this case, the crime rate is the dependent variable while the number of kids that get free lunch is the independent variable (because in theory, the crime rate is based off of the "free lunch" rate).


Results: The results for the linear regression model are found in Figure 1 and Figure 2.
Figure 1: Regression Analysis Equation of the Model

Figure 2: R-Square model of the Regression Analysis

In analyzing Figure 1 figures, the equation for the regression analysis is y = 21.819 + 1.685x. 21.819 is the constant, meaning that is where the equation crosses the y-axis, and 1.685 is the regression coefficient. The equation is a positive equation, meaning when the number of kids who obtain free lunch increases, the crime rate tends to increase. Also, the equation is significant at .005, meaning that the equation is significant at the 99% level and that there is a linear relationship between the number of kids who obtain free lunch, and the crime rate.

In analyzing Figure 2, the r-squared is .173, which on the 0-1 scale isn't the strongest trend line for the given data. However, in relating the r-squared back to the equation, the equation is significant at the 99% level, so even though the relationship isn't the strongest, it is significant.

Discussion: In analyzing the regression analysis done on the two variables, there seems to be a linear relationship between the number of kids who receive free lunch, and the crime rate despite the fact the r-squared is weak. So for example; if a new area of town was identified as having 30% kids with free lunch, in plugging the number into the equation y = 21.819 + 1.685(30), the crime rate would be 72.369 per 100,000 people. Despite the fact that the relationship between the two variables is significant at the 99% level, the r-squared is only .173, meaning its a weak relationship. If the r-squared were closer to 1, there might be more confidence in the relationship between free lunch and the crime rate, however because it's so low there isn't much confidence in the relationship.


Part 2


Introduction: For this part, we were given data associated with 911 calls per census tract in Portland, Oregon. The data set included variables such as the number of 911 calls per census tract, jobs, renters, number of people with no high school degree, alcohol sales, number of people unemployed, foreign born population, median income, and number of college grads, with the goal of seeing if there is any explanation for where higher proportion of calls come from. In this case, knowing if there's a relationship between the number of calls and other variables is useful for companies who want to know what factors influence 911 calls, and where to build a new hospital. 

Methods: In order to see which variables influence 911 calls the greatest three separate regression analysis's were done. The dependent variable in each of the regression analysis's was the number of 911 calls per census tract, while the independent variable varied per analysis. For the purposes of this assignment, the independent variables were chosen at random. 

The statistical software program SPSS was utilized to run regression analysis's. Once the three separate analysis's were run, the regression with the highest significant correlation was utilized to create a residual map in ArcMap. The highest significant correlation was utilized because it shows the greatest potential in explaining the relationship between 911 calls and other contributing factors.

Results: The three independent variables used were the number of people with no high school degree, number unemployed, and alcohol sales. In Figure 3 and Figure 4, the figures are analyzing the linearity between alcohol sales and 911 calls.
Figure 3: R-Squared Model of Relationship between Alcohol Sales and 911 calls

Figure 4: Linear Equation and Significance of the Model
In analyzing Figure 3, there seems to be a weak linear relationship between alcohol sales and the number of 911 calls. The coefficient of determination is .152, which is low on the 0-1 scale. However, in analyzing Figure 4, the significance level is lower than .05, meaning that despite the weak relationship, the relationship is significant at the 95% level. Because the relationship between the two variables is significant at the 95% level, we reject the null hypothesis (that there is no significant linear relationship between alcohol sales and the number of 911 calls), and state there is a significant relationship between the two. Also, it's important to note that the relationship is positive. The b-value for this model is 3.0695E-5, which means when calls increases by one, the alcohol sales also tend to increase by the b-value.

In Figure 5 and Figure 6, the figures are analyzing the relationship between the number of unemployed people per census tract, and 911 calls.
Figure 5: R-Squared Model of Relationship between Number of Unemployed and 911 Calls
Figure 6: Linear Equation and Significance of the Model
In analyzing Figure 5, there seems to be a moderate linear relationship between the number of people unemployed and 911 calls. The coefficient of determination is .543, which at least compared to Figure 3, is stronger by approximately .4. In analyzing Figure 6, the significance value is under .05, meaning that their is a significant linear relationship between the two variables. Because the regression is significant at the 95% level, we reject the null hypothesis (that there is no significant linear relationship between number of unemployed and the number of 911 calls), and state there is a significant linear relationship between the two variables. Also, the relationship is a positive relationship. The b-value for unemployed is .507, meaning that when the number of calls goes up by one, the number of unemployed people also increases by .507.

In Figure 7 and Figure 8, these figures are analyzing the relationship between the number of people without high school diplomas and the number of 911 calls.
Figure 7: R-Squared Model of Relationship between Number of People without High School Degrees, and 911 calls

Figure 8: Linear Equation and Significance of the Model

 In analyzing Figure 7, there seems to be a moderate linear relationship between the number of people without a high school diploma and 911 calls. The coefficient of determination is .567, which is the strongest out of all of the other regression analysis's; however, on a 0-1 scale it's about midway between 0 and 1, which means it isn't the strongest relationship. In analyzing Figure 8, the significance level is less than .05, meaning that the relationship is significant at the 95% level. Because the regression is significant at the 95% level, we reject the null hypothesis (that there is no significant linear relationship between the number of people who don't have high school diplomas and 911 calls), and state there is a linear relationship between the two variables. Also, the relationship is a positive one. The b-value is .166, which means when the number of calls goes up by 1, the number of people who don't have a high school diploma increases by .166.

In comparing the three regression analysis's together, they all were significant at the 95% level and they all were positive relationships. However, the number of unemployed and the number of people without a high school diploma's coefficient of determination were noticeably higher than the alcohol sales, meaning there seems to be a stronger relationship between those two variables and the number of 911 calls. The highest coefficient of determination was the relationship between the number of people without high school diplomas and the number of 911 calls, which means companies should be most confident with number of people without high school diplomas determining the number of 911 calls (at least compared to the other two analyses).

In knowing the strongest linear relationship was between people without high school diplomas and 911 calls, a residual map was created showing the variability of each census tract. Figure 9 is a choropleth map showing the number of 911 calls per census tract, while Figure 10 is a residual map of the number of people without high school diplomas and 911 calls.
Figure 9: Choropleth Map of the Number of 911 Calls per Census Tract

Figure 10: Residual Map of Low Education Levels versus Number of 911 Calls
In analyzing Figure 9, there seems to be a concentration of a high number of 911 calls in the north-central part of the city, and one on the south-east part of the city. There also seems to be lower concentrations of 911 calls on the outer ends of the city, at least comparatively. In adding a variable to the mix to see how each census tract's point corresponds to the linear trend line, Figure 10 shows some high variability on the two census tracts on the north side of town (the two dark red ones). The dark red census tracts means that the two values are a good amount greater than what their corresponding value should be on the trend line. However, in analyzing the map as a whole, a majority of the tracts wall within the -1.5-1.5 range (or  either light blue, yellow, or light red), which means the residual values are relatively close to fitting the trend line. In relating these map values back to the regression statistics, the coefficient of determination seems to correlate with what is displayed on the map. The coefficient of determination value was .567-showing a moderate linear relationship-and what shows on the map is a majority of residuals between -1.5 and 1.5 with a couple of outliers, which seems representative of the coefficient of determination value.

Conclusion: Overall, there seemed to be the strongest linear relationship with the number of people without high school diplomas and 911 calls. The number of people unemployed and 911 class also had a moderate relationship competitive to the high school diploma one, however the linear relationship between alcohol sales and 911 calls was by far the weakest relationship, due to its low coefficient of determination. If a company were to utilize these statistics to determine factors that contribute to a high 911 call rate, the number of people without high school diplomas has the strongest linear relationship out of the three independent variables analyzed.





Monday, December 4, 2017

Assignment 5: Correlation and Spatial Autocorrelation

Part 1

Introduction: The goal of this lab is to become familiar with the statistic correlation. Correlation is the study on how two variables relate to one another. Generally, the variables already are related in some way (i.e. free throw percentage and height: the relation is through basketball), and the statistic of correlation determines whether or not the two variables are associated with one another. In calculating the correlation statistic, the values range from 1 to -1. If a correlation statistic is close to either 1 or -1, that means they have a strong positive or negative relationship. In contrast, if the correlation value is closer to zero, that means the two variables have a weak positive or negative relationship. If the correlation is zero, then that means there is no relationship between the two variables.

A way of understanding correlation from a visual perspective is to utilize a scatterplot. Scatterplots help determine whether or not there's a strong or weak correlation between the two variables using a graph. An example of a strongly correlated scatterplot is in Figure 1, where most of the data follows a linear line.

Figure 1: Example of strongly correlated scatterplot. Taken from https://www.mrholloman.net/PS/Notes/LFNotes09/image006.png

In contrast, an example of a weaker correlated scatterplot is Figure 2, where the data follows no describable pattern.
Figure 2: Weaker Correlated Scatterplot. Taken from https://static1.squarespace.com/static/

Assignment Questions:

1.) For this question, we were given data to create a scatterplot in Excel, and find the correlation statistic in the program SPSS. The two variables given to us were the distance away from the sound source measured in feet, and the sound level measure in dB.

Figure 3 depicts the scatterplot of the data, whereas Figure 4 depicts the calculated correlation statistic.


Figure 3: Scatterplot of the data

Figure 4: SPSS calculated statistic of the two variables
In analyzing Figure 3 and Figure 4, it seems like there is a strong negative correlation between the the distance away from a sound source, and the sound level. The null hypothesis states that there is no significant relationship between distance and sound level; however, we reject the null hypothesis because the correlation is significant at the 99% level (given the two stars next to the "-.896"). By rejecting the null, that means their is a relationship between distance and sound level.


2.) For this assignment, we were given data on Detroit and had to run a correlation on the data to see which two variables correlate (located in Figure 5).

The variables are:
White = White population for the 1000 census tracts in and around Detroit
Black = Black populations
Asian = Asian Pop.
His = Hispanic Pop
BachDegree = Number with a Bachelor’s Degree
MedHHInc = Median Household Income
MedHomeValue = Median Home Value
Manu = Number of Manufacturing Employees
Retail = Number of Retail Employees
Finance = Number of Finance Employees

Figure 5: Correlation statistics of Detroit

In analyzing the statistics, the highest correlation is between median household income and median home value at .883. The relationship between median household income and median home value is positive and significant at the 99% level, meaning the null hypothesis (that the two variables' relation is not statistically significant), is rejected, meaning there is a correlation between the two .

The next highest correlation is bachelor degrees and both median household income/median home value at .753. The statistic is a positive number, meaning the higher the number of bachelor degrees, the higher the median home value/median household income. The number is also statistically significant at the 99% level, meaning the null hypothesis (that the two variables' relation is not statistically significant), is rejected, meaning there is a correlation between the two.

The largest negative correlation is between white populations and black populations at -.604. The fact the relationship between those two variables is negative means the greater the white population in a given area, the smaller the black populations (or vise-versa). Also, the statistic is significant at the 99% value, meaning the null hypothesis (that the two variables' relation is not statistically significant), is rejected, meaning there is a correlation between the two.



Part 2

Introduction: The goal of this lab is to become familiar with spatial autocorrelation. Spatial autocorrelation is determining whether variables in space are correlated. For example, if the same variable is measured throughout each neighborhood, one can determine if there's a correlation between the neighborhoods and the variable through spatial autocorrelation.

In measuring spatial autocorrelation, one uses the Moran's I. The Moran's I is a similar measurement to the regular, non-spatial correlation statistic. Autocorrelation statistics closest to 1 mean there is a strong positive correlation between neighborhoods and the variable (meaning the neighborhoods are alike), while statistics closest to -1 means there is a strong negative correlation (meaning the neighborhoods are not alike). The Moran's I also utilizes four quadrants of comparison using an X, Y graph. The quadrants are divided into High, High (meaning high values are surrounded by other high values); High, Low (meaning high values are surrounded by low values); Low, High (meaning low values are surrounded by high values), and Low, Low (meaning low values are surrounded by low values). The values can be placed on a map or a graph called a LISA map to determine where spatial autocorrelations are high, low, or outliers in relation to a given area.

For this assignment, we were given data from the Texas Election Commission for the 1980 and 2012 presidential elections. The data we were given to analyze relates to Democratic votes per county in Texas, to see if there were any changes in voting patterns from 1980 to 2012. We were also given Hispanic population data from 2010 to see if population variables had any impact on voting patterns.

Methods: In order to see if there is any clustering of voting patterns throughout the state, use of the programs Excel, SPSS, and GeoDa were utilized for the creation of various statistics, graphs, and maps. Excel was useful in the creation of scatterplots for comparing correlations between population variables and voter turnout/percent voted democrat. SPSS was useful in the creation of correlation statistics for similar reasons Excel was utilized. GeoDa was useful in creating Moran's I graphs and corresponding maps for seeing if there was any clustering of the statistics.

GeoDa was the main program utilized in determining the spatial autocorrelation of the variables given to us (variables given to us were voter turnout percent for 1980 and 2012, percent democrat vote for 1980 and 2012, and percent hispanic populaion). Once all of the data was download into a shapefile, a new projected was created in GeoDa. Before calculating spatial autocorrelation statistics however, a weights manager needed to be employed so there was a spatial weight to the data. The contiguity utilized was a rook contiguity (meaning the program is only going to relate counties bordering each other), and then the statistics were all set to calculate.

After all of the Moran's I Quadrants and the Spatial Autocorrelation Maps were created, SPSS was utilized to see if there was any correlation between the variables. SPSS was utilized to see if there were any correlation between Hispanic populations and the other variables.

Results: In producing the results, a multitude of spatial autocorrelation maps and Moran's I quadrants were created.

Regarding the percent of Democratic votes in 1980, Figure 6 and Figure 7 represent the Moran's I quadrant and the spatial auto correlation map.

Figure 6: Moran's I Quadrant of the Percent Democratic Vote, 1980 

Figure 7: Spatial Autocorrelation Map of the Percent Democratic Vote, 1980

In analyzing Figure 6 and Figure 7, it seems there is a high cluster of percentage democratic votes in southern Texas, while simultaneously a high cluster of  "low percentage democrat" votes in the northern part of Texas. In analyzing the Moran's I, the statistic calculated on top of the quadrant (while not the most legible) is .57, meaning there is a moderate spatial autocorrelation between the counties and the percent of democrat vote.


Regarding the percent of Democratic votes in 2012, Figure 8 and Figure 9 represent the Moran's I quadrant and the spatial auto correlation map.

Figure 8: Moran's I Quadrant of the Percent Democratic Vote, 2012

Figure 9: Spatial Autocorrelation Map of the Percent Democratic Vote, 2012

In analyzing Figure 8 and Figure 9, there was some spatial change in the counties that voted democrat. Southern Texas still held a high-high spatial autocorrelation between the counties, meaning there was a high proportion of democrat votes in the red counties that relate to each other; however, there also seemed to be more high-high spatial autocorrelation in the western part of the state in comparison to Figure 7. In contrast, a low-low concentration of democrat votes held reign in the northern part of the state; however there seemed to be more clusters of low-low concentrations in the center part of the state compared to Figure 7. The Moran's I statistic is also higher in 2012 compared to 1980. The 2012 statistic is .69, compared to .57 in 1980, so in 2012 it seems to be more spatially correlated, however it is still only moderately correlated.

Regarding the percent of voter turnout in 1980, Figure 10 and Figure 11 represent the Moran's I and spatial autocorrelation map.
Figure 10: Moran's I Quadrant of the Percent Voter Turnout, 1980

Figure 11: Spatial Autocorrelation Map of the Percent of Voter Turnout, 1980

In analyzing Figure 10 and Figure 11, there seems to be a cluster of low-low counties in southern and eastern Texas, meaning counties with low voter turnout are surrounded by other counties of low voter turnout. In contrast, there seems to be a cluster of high-high counties in central and northern Texas, meaning counties with high voter turnout are surrounded by other counties with high voter turnout. However, the Moran's I statistic is .33, meaning that there is a weak spatial autocorrelation between counties and voter turnout, at least in 1980.

Regarding the percent of voter turnout in 2012, Figure 12 and Figure 13 represent the Moran's I and spatial autocorrelation map.
Figure 12: Moran's I Quadrant of the Percent Voter Turnout, 2012

Figure 13: Spatial Autocorrelation Map of the Percent of Voter Turnout, 2012

In analyzing Figure 12 and Figure 13, there still seems to be a cluster of low-low counties in southern Texas, and a cluster of high-high counties in comparison to Figure 11. However, the cluster of high-high counties in Northern Texas that presented itself in Figure 11 seems to have broken up in Figure 13--or at least only presented itself in the northeast corner of the state. In analyzing Figure 12, it seems the Moran's I statistic decreased compared to 1980. In 1980, the statistic was .46-a moderate spatial correlation--however in 2012 the statistic was .33, a weaker spatial autocorrelation, meaning there is less correlation of voter turnout between counties in 2012.

Regarding percent Hispanic population in 2010, Figure 14 and Figure 15 represent the Moran's I and spatial autocorrelation map.
Figure 14: Moran's I Quadrant of Percent Hispanic Population, 2010

Figure 15: Spatial Autocorrelation Map of Percent Hispanic Population, 2010

In analyzing Figure 14 and Figure 15, there seems to be a significant cluster of high-high counties stretching from southwestern Texas to southern Texas, meaning counties of high proportions of Hispanic people are surrounded by other counties with high proportions of Hispanic people. In contrast, there seems to be a significant low-low cluster in eastern Texas, meaning counties with low proportions of Hispanic people are surrounded by other counties with low proportions of Hispanic people. In analyzing Figure 14, the Moran's I statistic is .77, which means there is a moderately high spatial autocorrelation between counties and the percentage of Hispanic populations.

In bringing all of the variables together to see if there was any correlation between the five variables, Figure 16 represents a correlation matrix of the variables to see if population variables had any correlation with voting patterns.


Figure 16: Correlation Matrix of the Variables
In analyzing the statistics, there seems to be a high positive correlation between the percent of Hispanic people per county, and the percent Democrat vote in 2012, which means the higher proportion of Hispanic people per county, the more likely that county will vote Democrat. In contrast, there seems to be a high negative correlation between percent of Hispanic people per county and Voter Turnout in 2012, meaning the higher proportion of Hispanic people per county, the less likely there will be a high voter turnout. Both correlations are also significant at the 99% level, meaning the null hypothesis is rejected (the null hypothesis meaning that the two variables's relation is not statistically significant), and there is a correlation between percent Hispanic/Percent Democrat vote in 2012, and Percent Hispanic/Percent Voter Turnout in 2012.

In comparing the changes in correlation between 1980 and 2012 between the Percent Hispanic and the Percent Democrat Vote, the correlation between the two spiked dramatically. The correlation in 1980 was .09, a weak correlation between the two variables; however, in 2012 the correlation became .718, a high positive correlation between Percent Hispanic and Percent Democrat vote.

In comparing the changes between 1980 and 2012 between Percent Hispanic and the Percent Voter Turnout, the correlations between the two increased negatively. The correlation in 1980 was -.407, meaning there is a low correlation between the two variables; however, in 2012 the correlation became -.718, which is a high negative correlation between Percent Hispanic and Percent Voter Turnout.

Conclusions: In the utilization of spatial autocorrelation and correlation statistics, it was found that counties with a high percentage of Hispanic populations also tended to vote a high percentage for Democrat, however exhibited a lower voter turnout. The data was found to be significant at the 99% level, and the clusters were generally found to be in the southern portion of the state, meaning the southern counties exhibited these voting behaviors.

Sources: http://factfinder2.census.gov/faces/nav/jsf/pages/index.xhtml










Monday, November 13, 2017

Assignment 4: Hypothesis Testing, Z-Testing and T-Testing

Part 1

Introduction: The goal of this lab is to become familiar with hypothesis testing. Hypothesis testing is a way to test whether or not certain data is statistically significant to its corresponding average. So for example, lets say someone wanted to see if people in one neighborhood on average went to the grocery store way more often than other neighborhoods. What they would do then is devise a hypothesis test to see not just if people in one neighborhood shop at the grocery store more often, but if they do it so much more often that it is statistically significant. 

In order to develop a hypothesis, one must be familiar with the specific model. The hypothesis test model follows this format: 

1.) State the Null Hypothesis
--i.e. There is no significant difference between the sample mean and the observed mean

2.) State the Alternative Hypothesis
--i.e. There is a significant difference between the sample mean and the observed mean

3.) Choose a statistical test
--Either Z-Test or T-Test

4.) Chose level of significance
--Usually between 90%-99%

5.) Test Hypothesis
--Calculate the Z-Test or T-Test

6.) Make decision about null and alternative hypothesis
--Either one "rejects" or "fails to reject" the null hypothesis (meaning the sample either "is" or "is not" statistically significant from the observed mean)

To determine if the data is statistically significant, one would use either a Z-test or a T-test. A Z-Test is generally used for data where n > 30 (or the number of samples taken is greater than 30), and it is an equation Figure 1 to help compare the sample average with the observed average. The x-bar is the sample average, the mu is the observed average, the s is the standard deviation of the sample average, and n is the number of samples taken. 
Figure 1: Z-Test equation taken from study.com. 
A T-Test is similar, however one would only use that test if n <30 (or the number of samples taken is less than 30). The T-test equation is the same as Figure 1.  The main difference between the z test and the t test lies in the chart to use, where the z-chart is based on probabilities and the t-chart is based on degrees of freedoms. 

After determining a test statistic to use, one determines the significance level, whether its a one-tail versus two-tailed kind of test (which is usually gathered through a literature review of whatever research is desired, however for purposes of this assignment the significance levels are given). After determining the significance level, one finds the corresponding probability on either the Z-chart or the T-chart (so for example: if someone's significance level is at 95%, one would go to the corresponding chart to find the Z-value that is closest to .95). 

After determining a significance level, one uses either a z or t test to see if the sample is so out of the ordinary compared to the observed mean, that it's statistically significant. Usually, if the z or t value is greater (or less, depending on the significance level) than the corresponding significance level's z or t value, then one can determine that their sample mean is significantly different than the observed mean. 

Assignment Questions: 

1.) For this question, we had to fill out the significance levels, whether or not a T-Test or a Z-Test should be used, and the corresponding z or t value (located in Figure 2).  


Figure 2: A chart of testing examples

2.) For this question, we were posed a question, and had to see whether or not the respective crop output was significantly different statistically from their means.  

A Department of Agriculture and Live Stock Development organization in Kenya estimate that yields in a certain district should approach the following amounts in metric tons (averages based on data from the whole country) per hectare: groundnuts. 0.55; cassava, 3.8; and beans, 0.28.  A survey of 23 farmers had the following results

μ             σ
                Ground Nuts      0.51        0.3
                Cassava                3.4          .74

                Beans                    0.33        0.13

Ground Nuts Hypothesis Test: 

1.) There is no significant difference between the sample average yield and the observed average yield. 

2.) There is a significant difference between the sample average yield and the observed average yield. 

3.) A T-Test will be utilized because the number of samples is less than 30. 

4.) The significance level is .05 and it will be a two-tailed test. The corresponding t-values are 2.074 and -2.074. 

5.) Calculate T-Test (sample mean = .51, observed mean is .55, standard deviation is .3, n is 23) 

((.51-.55)/(.3/ (square root of 23) ) = -.694

6.) We fail to reject the null hypothesis, because -.694 is within the range of -2.074 to 2.074. 


Cassava Hypothesis Test: 

1.) There is no significant difference between the sample average yield and the observed average yield. 

2.) There is a significant difference between the sample average yield and the observed average yield. 

3.) A T-Test will be utilized because the number of samples is less than 30.

4.) The significance level is .05 and it will be a two-tailed test. The corresponding t-values are 2.074 and -2.074. 

5.) Calculate T-Test (sample mean = 3.4, observed mean is 3.8, standard deviation is .74, n is 23). 

((3.4-3.8) / (.74 / square root of 23)) = -2.592

6.) We reject the null hypothesis, because -2.592 falls outside of the range -2.074 to 2.074

Beans Hypothesis Test:

1.) There is no significant difference between the sample average yield and the observed average yield.

2.) There is a significant difference between the sample average yield and the observed average yield. 

3.) A T-Test will be utilized because the number of samples is less than 30.

4.) The significance level is .05 and it will be a two-tailed test. The corresponding t-values are 2.074 and -2.074.

5.) Calculate T-Test (sample mean = .33, observed mean = .28, standard deviation = .13, n = 23)

((.33-.28) / (.13 / square root of 23) ) = 1.844

6.) We fail to reject the null hypothesis because 1.844 falls within the range of -2.074 to 2.074.


The probability values for each crop are:

Ground Nuts: .246

Cassava: .00856

Beans: Between .95652 and .96403


In comparing the results, the beans and the ground nuts both failed to reject the null hypothesis. Both fell within the range of -2.074 to 2.074, which means their data is not statistically significant. The cassava output however rejected the null hypothesis. The t-score of -2.592 fell outside of the range of -2.074 to 2.074, which means their data is statistically significant. In examining the probabilities, both cassava and ground nuts produced a probability between the t tests probability (because it is a two tailed t test at a 95% confidence interval, the t-test probability should be between .025 and .975 in order to fail to reject the null), which means they failed to reject the null. However, the cassava fell outside of the probability, falling at .00856 which is less than .025, which means the null is rejected for cassava.

3.) For this problem, the scenario was posed:

A researcher suspects that the level of a particular stream’s pollutant is higher than the allowable limit of 4.4 mg/l.  A sample of n= 17 reveals a mean pollutant level of 6.8 mg/l, with a standard deviation of 4.2.  What are your conclusions?  (one tailed test, 95% Significance Level). What is the corresponding probability value of your calculated answer? 

To start with a hypothesis test:

1.) There is no significant difference between the sample allowable limit and the observed average allowable limit.

2.) There is a significant difference between the sample allowable limit and the observed average allowable limit. 

3.) A T-Test will be utilized because the number of samples is less than 30.

4.) The significance level is .05 and it will be a one-tailed test. The corresponding T-value is 1.746.

5.) Calculate T-Test (sample mean = 6.8, observed mean = 4.4, standard deviation = 4.2, n = 17)

((6.8-4.4) / (4.2 / square root of 17)) = 2.356

6.) We reject the null hypothesis because 2.356 is greater than 1.746.

The probability is between .96945 and .98554

In conclusion, the t-value for the sample was 2.356, which is greater than the significance level t-value of 1.746, meaning that there is a significant level of pollutant in the stream. The corresponding probability for the significance level is .95, and the probability for the corresponding probability value for my calculated answer was between .96945 and .98554, which also reinforces rejection of the null hypothesis. 


Part 2

Introduction: For this part of the assignment, we were given shapefiles of block groups: one for Eau Claire County, and one for the city of Eau Claire. The shapefiles contained data for the average home prices per block group, and we were posed the question "is the average value of homes per block group in Eau Claire the city significantly different from the block groups in Eau Claire county." 

Methods: In order to determine whether or not the average value of homes per block group in Eau Claire City was significantly different from the block groups in Eau Claire County, shapefile data for both Eau Claire City and Eau Claire County were utilized. Using the data, a hypothesis test was utilized. Stemming from the utilization of a hypothesis test, statistics also had to be calculated. Using the statistics function in Arc Map, the average home values per block group for Eau Claire County were obtained, and the average home values per block group for Eau Claire City. Also, the standard deviation and number of block groups for Eau Claire City's home values were obtained for the utilization of either a z or a t test. 

Results: 

To provide the hypothesis test: 

1.) There is no significant difference between the average home price of Eau Claire City's block groups and Eau Claire County's block groups. 

2.) There is no significant difference between the average home price of Eau Claire City's block groups and Eau Claire County's block groups. 

3.) A Z-Test will be utilized because the number of samples is greater than 30.

4.) The significance level is .05, and it will be a two-tailed test because the statistic could be either significantly lower or higher than the observed average. The corresponding z values are -1.96 and 1.96

5.) Calculate Z-Test (EC City = 151,876.51, EC County = 169,438.13, EC City Standard Deviation = 49,706.92, n = 53)

((151,876.51 - 169,438.13) / ((49,706.94 / (square root 53)) = -2.57

6.) We reject the null hypothesis, between -2.57 falls outside of the range of -1.96 to 1.96.

By rejecting the null hypothesis, it is concluded that the average value of homes per block group in Eau Claire the city, is significantly different than the average price of homes for the county. -2.57 falls under the the range of -1.96-1.96, which means the average house price per block in Eau Claire City is significantly lower than the average price of homes for the county. And if one looked at the map in Figure 1, the data represents the findings in the hypothesis test. The black outlined block groups represents the block groups within the city of Eau Claire, and a majority of the block groups within the city fall under the lowest two categories of housing price.

Figure 1: Map of Average Housing Price per Block Group in Eau Claire County


Conclusion: Using both the hypothesis test and the map in Figure 1, it is evident that the average house prices within Eau Claire the city are significantly lower than the ones for the county. The map show a majority of Eau Claire city block groups' average housing prices falling within the two lowest housing categories, and the hypothesis test produced a z-value of -2.57, which falls outside the corresponding z values for a two-tailed z test with a 95% confidence interval. 








Wednesday, October 25, 2017

Assignment 3: Statistical Analysis

Introduction: Housing foreclosures are an issue in certain parts of the country, and it might affect some census tracts in Dane County, Wisconsin. In this report, the number of housing foreclosures from 2011 and 2012 will be investigated and compared in order to determine if Dane County officials need to be worried about an increase in foreclosures. Some of the questions this research hopes to answer are "how have the number of foreclosures changed from 2011 to 2012"; "if the number of foreclosures are increasing year-to-year, what is the probability that they continue to increase or decrease in subsequent years;" and "what number of foreclosures for all of Dane County will be exceeded 80% of the time, and 10% of the time?"

Methodology: In order to determine the change in foreclosures from 2011 to 2012, US Census Tract data was utilized. The US Census data was important because it provided the number of foreclosures for the years need. In relation to the data, a field was added to the data in ArcMap depicting the change in the number of foreclosures from year to year. This added field helps determine whether or not the number of foreclosures increased, decreased, or stayed the same.

Also, mean, median, standard deviation, and Z-score were calculated in order to better understand certain statistics associated with the number of foreclosures. Calculating the mean is important because it displays the average change in foreclosures between the years 2011-2012, and the average number of foreclosures for both years. However, calculating the median is also important because it ignores potential outliers, so it could represent a more balanced data representation. The standard deviation is important because it shows the variability of the changes from 2011-2012 for each census tract in relation to the mean, and for each year.

Z-Scores were calculated for 3 separate census tracts--tract number 25, 108, and 120.01 for 2011 and 2012 (so 6 z-scores in total) for sampling purposes. To provide a definition: a z-score is based on the observation's relation to the mean. So for example: if the mean is 12, and the observation is also 12, the z-score will be 0 because they are the same number (if the obsersation is greater than 12, the z-score will be greater than 0. If the observation is less than 12, the z-score will be less than 0. Usually z-scores fall in the ± 3 range). Z-scores are important for analyzing the data because it shows probability of future foreclosures in a given census tract (which can be obtained using the chart in Figure 1.
Figure 1: Z-Score Chart
In order to calculate Z-Score, one would subtract the observation by the mean, then divide by the standard deviation.

Results: To provide some statistics associated with foreclosures:

Foreclosures in 2011:
Mean = 11.39 foreclosures per tract
Median = 11.00 foreclosures per tract
Standard Deviation = 8.78

Foreclosures in 2012:
Mean = 12.30 foreclosures per tract
Median = 10.00 per tract
Standard Deviation = 9.91

In comparing the number of foreclosures between two years, the average number of foreclosures rose by .91 properties, however the median dropped from 11 foreclosures per tract to 10. The increase in foreclosures seems to mean certain tracts' foreclosures increased somewhat dramatically from one year to the next, which increased the mean. The standard deviation also increased from 2011 to 2012, which means there is more variability in the number of foreclosures in relation to the mean (i.e. if the standard deviation were like 1 for example, the number of foreclosures would be clustered around the mean, verses if it's higher then the number of foreclosures aren't as clustered around the mean).

In mapping the change of foreclosures between 2011-2012, Figure 2 represents either the increase or decrease in foreclosures between years. 
Figure 2: Map of changes in number of foreclosures from 2011-2012

As depicted by Figure 2, the light blue/dark blue colors represent a decrease in foreclosures between 2011-2012; the yellow represents no change in the number of foreclosures, and the orange/red represent an increase in the number of foreclosures. It seems that  increase in foreclosures are situated in the far-eastern and northwestern part of the county, whereas decreases seemed to happen most in the center of the county.

Also, another map depicting the standard deviations for foreclosures in both years was created to see the rate of foreclosure deviating from the mean, located in Figure 3. 
Figure 3: Comparative Map of Standard Deviation of Foreclosures from 2011-2012
 To reiterate, the mean number of foreclosures for 2011 was 11.39 per tract, while for 2012 the mean number was 12.30. It seems that in 2011, the northern tracts exhibited a high positive standard deviation, which means the number of foreclosures is higher than the mean; whereas, in 2012 the standard deviations are still positive, however not as large of a standard deviation as the 2011 tracts. It doesn't seem the rate of foreclosures deviated too much from year to year, especially in the central part of the county, which means the rate of foreclosures is staying consistent to the averages. A couple of the northern tracts decreased their standard deviation, which means the rate of foreclosures most likely went down for the tract.

Using the mean and standard deviation for 2012, in calculating probability using Z-scores, the Z-score for "exceeding 80%" was -.84. Assuming the patterns for 2012 hold the next year in Dane County, there is an 80% chance that there will be more than 3.98 foreclosures per census tract (which there can't be a fraction of a house foreclosed, so approximately 4 foreclosures per census tract). For "exceeding 10%", the Z-score was 1.28, and using the Z-score, there is a 10% chance foreclosures will exceed 24.98 (or approximately 25 foreclosures). If comparing the probability to tracts in the below map in Figure 3, there will be at least 4 foreclosures in most census tracts (minus a few red ones); however, there will probably be at least 25 foreclosures in the darkest and second darkest blue areas (i.e. Tract 120.01), because they already have a high number of foreclosures.

For sampling purposes, tracts 108, 25, and 120.01 were utilized to show how z-score can be used to calculate probability (as depicted in Figure 3. If it's too hard to see, 108 is the southwest one, 25 is the most north, and 120.01 is the most east). The 2011 and 2012 Z-scores for tracts 108, 25, and 120.01 are:

108: 2011 Z-Score is 2.01, 2012 Z-Score is 1.48
25: 2011 Z-Score is -.61, 2012 Z-Score is -.94
120.01: 2011 Z-Score is 1.78, 2012 Z-Score is 3.0

For tract 108, the Z-score was 2.01 in 2011 and 1.48 in 2012. Using the chart in Figure 1, that means out of all of the tracts in Dane county, that means in 2011 2.22% of the time foreclosures will exceed its original observation (which was 29 foreclosures), while in 2012 6.94% of the time the foreclosures will exceed its original observation (which was 27 foreclosures).

In tract 25, the Z-score was -.61, and in 2012 -.94. That means in 2011, 72.91% of all foreclosures will be greater than the original observation (which was 6), and in 2012 82.64% of all foreclosures will be greater than the original observation (which was 3).

In tract 120.01, the Z-score for 2011 was 1.78, while in 2012 it was 3.0. That means in 2011, 3.75% of the observations will be greater than the original observation (which was 27), while in 2012 .14% of the observations will be greater than the original observation (which was 42).

Conclusion: The purpose of this assignment was to determine how the number of foreclosures have changed from year to year per census tract, and the probability of increasing/decreasing of foreclosures in subsequent years. In comparing the number of foreclosures from 2011 to 2012, the mean rose by .91 foreclosures, however the median shrank by 1 foreclosure. The tracts stayed relatively consistent year-to-year in relation to the standard deviation, some decreased their standard deviation from year to year which means the number of foreclosures most likely went down. Most of the census tracts will have at least 3 foreclosures in their area; however, ones who have at least 25 are in the 90th percentile, which means certain tracts on the eastern part of the county (i.e. 120.01) are having houses foreclosed at a high rate.

Tuesday, October 10, 2017

Assignment 2: Standard Deviation and Mean Center

Part 1

Introduction: The purpose part 1 was to become familiar with the real world applications of statistics and how to calculate them. In this assignment, sample test scores from two different high schools were utilized. Multiple different kinds of statistics were calculated in order to compare the test scores from the two high schools. 

Definitions: Before delving into calculations, it is important to define each of the different kinds of statistics calculated. Range is taking the lowest value, and subtracting it from the highest value to display the differences in value. So for example, if the highest test score was a 192 out of 200, and the lowest was a 111, the range would be 192-111, which is 81. Mean is the average of all of the values, which is found by adding up all of the observations, then dividing them by the number of observations. So for test scores, if there were 5 test scores (lets say 153, 135, 120, 188, and 180), one would add up all of those values to equal 776, then divide it by 5 to equal a mean of 155.2. 

Median is finding the exact middle of the values if they were all ordered numerically. So if there are 7 test scores (lets say 3, 6, 7, 9, 10, 11, 12--they did really bad on this test), the median would be 9 because 9 is the exact middle (if there are an even number of observations, the exact middle is then the average of the two middle observations). Mode is finding the value seen the most in the data. So for example, if there are 10 test scores (lets say 128, 123, 153, 153, 152, 122, 153, 155, 153, 153), 153 would be the mode because there are the most test scores in that data that equal 153. 

Kurtosis is essentially how peaked or flat the data is when it is graphed. So for example, if the data is really peaked (i.e the line looks like Figure 1), the test scores are closer to the average. Whereas if the data is flat (i.e. the line looks like Figure 2), the test scores are farther away from the average. If a Kurtosis equals a value greater than 1, it is considered peaked, while if it is less than -1, it is considered flat.

Figure 1: A peaked graph (taken from http://personal.cityu.edu.hk/~meachan/Online%20Anthropometry/Chapter5/Ch5-3.htm) 

Figure 2: A flat graph (taken from http://personal.cityu.edu.hk/~meachan/Online%20Anthropometry/Chapter5/Ch5-3.htm)
Skewness refers to how much the data leans to the left or the right when referring to a normal distribution. So if a normal distribution looks like Figure 1, a skewed distribution might look like Figure 3. Skewed distributions can either be positive (leaning to the left) or negative (leaning to the right). With regards to calculations, 0 means there is no skewness, anything below 0 is a negative skewness, and anything above 0 is a positive skewness. 
Figure 3: An example on skewness (taken from https://en.wikipedia.org/wiki/Skewness)
Standard Deviation refers to how much the data deviates from the average. So for example with test scores: if the average is 150, and there is a standard deviation of 2, a majority of the students' test scores should fall between 150 + or - 2, because the standard deviation determines how the data will cluster around the average (if one were to add another two, i.e. 150 + or - 4, then the overwhelming majority will have their test scores fall between that spectrum). For standard deviation, there are two types of equations: normal standard deviation and sample standard deviation. Normal standard deviation takes into account all of the observations (so if there were 500 students taking a test, normal standard deviation would take into account all 500 students), while sample standard deviation only takes a select number of observations (so if someone wanted to calculate the standard deviation for 200 out of the 500 students, they would use a sample standard deviation equation). The two equations for each are located in Figure 4 and Figure 5.

Standard Deviation:
Figure 4: Standard Deviation (taken from http://libweb.surrey.ac.uk/library/skills/Number%20Skills%20Leicester/images/pic013.gif)
Sample Standard Deviation:
Figure 5: Sample Standard Deviation (taken from http://libweb.surrey.ac.uk/library/skills/Number%20Skills%20Leicester/page_19.htm)
The only difference between the two is in its division. In normal standard deviation, the top equation is divided by the total number of observations, while in sample the top equation is divided by the number of observations in the sample minus one.

Calculations: For this assignment, all of the statistics defined above were calculated with regards to the two high schools' test scores in Figure 6. The statistics on the left refer to North High School, while the ones on the right refer to Memorial.
Figure 7: The two high schools' test scores
 For North High School: Range = 83. Mean =160.92. Median = 164.5. Mode: 170. Kurtosis = -.056. Skewness = 2.42. Standard Deviation = 23.64.

For Memorial High School: Range = 91. Mean = 158.54. Median = 159.5. Mode = 120.
Kurtosis =1.83. Skewness = -.18. Standard Deviation = 27.16.

For Standard Deviation, the deviation calculated was a sample standard deviation because the whole student bodys' test scores were not utilized, and for the assignment standard deviation was calculated out by hand in Figure 8 to become more familiar with its calculation process.
Figure 8: Sample Standard Deviation calculated out by hand


Discussion: In comparing the two schools, there was a previous perception that the students at North fare worse off in tests than at Memorial. In looking at the statistics, that perception seems to be false. North students' average test score was 160.92, compared to Memorial's 158.54. Now, given there may be couple of outliers throwing off the data; however, the median test score for North was 164.5, while at Memorial the median test score was 159.5. The fact that both the North's median and mean were larger than Memorial's contradicts the negative perception that North has lower test scores. There were other statistics calculated for both the schools, however mean and median best illustrate and debunk the negative perception of North because they show the average test score each student earned with the mean, however they also ignore potential outliers with the median. The fact North has a higher mean and median contradicts the theory of "Memorial has better test scores," because it shows that their students earn higher average test scores, but also how outliers didn't affect the data too much with the higher median.


Part 2

Introduction: The purpose of part 2 is to understand the definitions of mean center and weighted mean center, and apply those learned definitions to a map. 

Definitions: Before delving into the mapping the mean center and weighted mean center, it is important to define the two terms. Mean Center is the geographical center of a given area. So for example, if someone wanted to calculate the mean center for Wisconsin, they would take the mean center of all of the counties in Wisconsin using X,Y coordinates, then take the average of the counties to develop the mean center. Weighted Mean Center however, takes into account the mean center, but also adds another variable to it. So for example, if someone wanted to calculate a weighted mean center for Wisconsin by population, they would determine the population for each county, then weigh them based on those levels (counties with higher population weigh greater than populations with lower ones). The purpose of a weighted mean center is to take into account where the geographical center is, but also where the weight of the variable is pulling the data (so with regards to population, if the mean center is located in the middle of the state, the population weight might force the mean center into a different direction, depending on how the population is distributed across the state).

Maps: For this part of the assignment, a map was created in Figure 1 to show the mean center of Wisconsin, and the weighted mean centers by population for the years 2000 and 2015.

Figure 1: Map of Mean Center and Weighted Mean Centers by Population for Wisconsin
Discussion: For this map, the mean center and the weighted mean centers by population in 2000 and 2015 are displayed. The mean center shows the geographical center of Wisconsin, taking into account the average centers for all 72 counties, then averaging the X and Y coordinates of each county in order to place it on the eastern part of Wood County. With regards to the weighted mean centers by population in the years 2000 and 2015, the populations seem to be located in the same general area. In 2000, the population weight drew the point down closer to the southeastern part of the state, and with the 2015 weighted mean center the population moved slightly southwest from the 2000 weighted mean center; however, the overall weight of the population seems to be located in the same general area.


Assignment 6: Linear Regression

Part 1 Introduction : The goal of this assignment is to understand how to use regression to determine correlations between two variables....