CUNY DATA606 - Lab 6

Zachary Herold Novermber 5, 2018

## 
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics 
## This package is designed to support this course. The text book used 
## is OpenIntro Statistics, 3rd Edition. You can read this by typing 
## vignette('os3') or visit www.OpenIntro.org. 
##  
## The getLabs() function will return a list of the labs available. 
##  
## The demo(package='DATA606') will list the demos that are available.

In August of 2012, news outlets ranging from the Washington Post to the Huffington Post ran a story about the rise of atheism in America. The source for the story was a poll that asked people, “Irrespective of whether you attend a place of worship or not, would you say you are a religious person, not a religious person or a convinced atheist?” This type of question, which asks people to classify themselves in one way or another, is common in polling and generates categorical data. In this lab we take a look at the atheism survey and explore what’s at play when making inference about population proportions using categorical data.

The survey

Take a moment to review the report then address the following questions.

  1. In the first paragraph, several key findings are reported. Do these percentages appear to be sample statistics (derived from the data sample) or population parameters?

These findings are sample statistics. The population in question is the entire human population, and direct calculation of global population parameters are prohibitively expensive to measure.

  1. The title of the report is “Global Index of Religiosity and Atheism”. To generalize the report’s findings to the global human population, what must we assume about the sampling method? Does that seem like a reasonable assumption?

To generalize the results, we must assume that the samples chosen are representative of the overall population and randomly selected. There are several forms of bias (including reporting bias) which make the results somewhat skeptical.

The data

Turn your attention to Table 6 (pages 15 and 16), which reports the sample size and response percentages for all 57 countries. While this is a useful format to summarize the data, we will base our analysis on the original data set of individual responses to the survey.

  1. What does each row of Table 6 correspond to? What does each row ofatheism correspond to?

Each row represents a country in which the religiosity survey was taken.

## 'data.frame':    88032 obs. of  3 variables:
##  $ nationality: Factor w/ 57 levels "Afghanistan",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ response   : Factor w/ 2 levels "atheist","non-atheist": 2 2 2 2 2 2 2 2 2 2 ...
##  $ year       : int  2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...

In the atheism.Rdata dataset, there are 88032 rows, each an observation in a particular country, with a particular self-categorization, and a year.

  1. Using the command below, create a new dataframe called us12 that contains only the rows in atheism associated with respondents to the 2012 survey from the United States. Next, calculate the proportion of atheist responses. Does it agree with the percentage in Table 6? If not, why?
## [1] 0.0499002

Table 6 shows the proportion of self-proclaimed atheists to be 5%, matching the result we derived from the dataframe after rounding.

Inference on proportions

  1. Write out the conditions for inference to construct a 95% confidence interval for the proportion of atheists in the United States in 2012. Are you confident all conditions are met?

Conditions for inference are as follows:

(1.) Random sample or randomized experiment (2.) ONE of the following: a) population is normally distributed b) sample size is large for CLT c) sample data shows evidence of normality with no outliers (boxplot, normal probability plot) (3.) Independent (N > 10n)

## [1] 2004

We assume that the methodology of the survey was such to provide a random sample. The sample size is more than sufficient for the Central Limit Theorm to apply. Also independence is maintained with the sample size of 2004 constituting less than 10% of the overall population of atheists.

If the conditions for inference are reasonable, we can either calculate the standard error and construct the interval by hand, or allow the inference function to do it for us.

## Warning: package 'BHH2' was built under R version 3.5.1
## Warning: package 'lmPerm' was built under R version 3.5.1
## Single proportion -- success: atheist 
## Summary statistics:

## p_hat = 0.0499 ;  n =  1002 
## Check conditions: number of successes = 50 ; number of failures = 952 
## Standard error = 0.0069 
## 95 % Confidence interval = ( 0.0364 , 0.0634 )
  1. Based on the R output, what is the margin of error for the estimate of the proportion of the proportion of atheists in US in 2012?
## [1] 0.0135

It is 1.35%.

  1. Using the inference function, calculate confidence intervals for the proportion of atheists in 2012 in two other countries of your choice, and report the associated margins of error. Be sure to note whether the conditions for inference are met.
##  [1] Afghanistan                                 
##  [2] Argentina                                   
##  [3] Armenia                                     
##  [4] Australia                                   
##  [5] Austria                                     
##  [6] Azerbaijan                                  
##  [7] Belgium                                     
##  [8] Bosnia and Herzegovina                      
##  [9] Brazil                                      
## [10] Bulgaria                                    
## [11] Cameroon                                    
## [12] Canada                                      
## [13] China                                       
## [14] Colombia                                    
## [15] Czech Republic                              
## [16] Ecuador                                     
## [17] Fiji                                        
## [18] Finland                                     
## [19] France                                      
## [20] Georgia                                     
## [21] Germany                                     
## [22] Ghana                                       
## [23] Hong Kong                                   
## [24] Iceland                                     
## [25] India                                       
## [26] Iraq                                        
## [27] Ireland                                     
## [28] Italy                                       
## [29] Japan                                       
## [30] Kenya                                       
## [31] Korea, Rep (South)                          
## [32] Lebanon                                     
## [33] Lithuania                                   
## [34] Macedonia                                   
## [35] Malaysia                                    
## [36] Moldova                                     
## [37] Netherlands                                 
## [38] Nigeria                                     
## [39] Pakistan                                    
## [40] Palestinian territories (West Bank and Gaza)
## [41] Peru                                        
## [42] Poland                                      
## [43] Romania                                     
## [44] Russian Federation                          
## [45] Saudi Arabia                                
## [46] Serbia                                      
## [47] South Africa                                
## [48] South Sudan                                 
## [49] Spain                                       
## [50] Sweden                                      
## [51] Switzerland                                 
## [52] Tunisia                                     
## [53] Turkey                                      
## [54] Ukraine                                     
## [55] United States                               
## [56] Uzbekistan                                  
## [57] Vietnam                                     
## 57 Levels: Afghanistan Argentina Armenia Australia Austria ... Vietnam

India

## Single proportion -- success: atheist 
## Summary statistics:

## p_hat = 0.0302 ;  n =  1092 
## Check conditions: number of successes = 33 ; number of failures = 1059 
## Standard error = 0.0052 
## 95 % Confidence interval = ( 0.0201 , 0.0404 )
## [1] 0.0101

For India, the 95 % Confidence interval is ( 0.0201 , 0.0404 ), with a margin of error of 0.0101. Conditions of inference are met.

Germany

## Single proportion -- success: atheist 
## Summary statistics:

## p_hat = 0.1494 ;  n =  502 
## Check conditions: number of successes = 75 ; number of failures = 427 
## Standard error = 0.0159 
## 95 % Confidence interval = ( 0.1182 , 0.1806 )
## [1] 0.0312

For Germany, the 95 % Confidence interval is ( 0.1182 , 0.1806 ), with a margin of error of 0.0312. Conditions of inference are met.

How does the proportion affect the margin of error?

We plot the two vectors against each other to reveal the relationship between probability and margin of error.

  1. Describe the relationship between p and me.

ME is at its max when p * (1-p) is at its max.

The first derivative of p * p^2 is equal to 1 - 2p, which equals 0 when maximized. This can be calculated when p = 0.5. As the proportion deviates from 50%, the Margin of Error diminishes.

Success-failure condition

Here we investigate the interplay between \(n\) and \(p\) and the shape of the sampling distribution by using simulations. To start off, we simulate the process of drawing 5000 samples of size 1040 from a population with a true atheist proportion of 0.1. For each of the 5000 samples we compute \(\hat{p}\) and then plot a histogram to visualize their distribution.

  1. Describe the sampling distribution of sample proportions at \(n = 1040\) and \(p = 0.1\). Be sure to note the center, spread, and shape.
    Hint: Remember that R has functions such as mean to calculate summary statistics.
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.07019 0.09327 0.09904 0.09969 0.10577 0.12981
## [1] 0.009287382

Both the median and mean are close to the point estimate of 0.10. The curve seems to be normal, as the min and max are slightly over 3 standard deviations from the mean. The shape is unimodal and nearly symmetrical.

## [1] 3.242861
## [1] -3.176104
  1. Repeat the above simulation three more times but with modified sample sizes and proportions: for \(n = 400\) and \(p = 0.1\), \(n = 1040\) and \(p = 0.02\), and \(n = 400\) and \(p = 0.02\).

Describe the three new sampling distributions.

Based on these limited plots, how does \(n\) appear to affect the distribution of \(\hat{p}\)? How does \(p\) affect the sampling distribution?

As sample size (n) increases, the tightness about the sample mean increases. The spread increases as n decreases. The probability largely determines the sample mean, and thus the point estimate.

  1. If you refer to Table 6, you’ll find that Australia has a sample proportion of 0.1 on a sample size of 1040, and that Ecuador has a sample proportion of 0.02 on 400 subjects. Let’s suppose for this exercise that these point estimates are actually the truth. Then given the shape of their respective sampling distributions, do you think it is sensible to proceed with inference and report margin of errors, as the reports does?
## [1] 1039
## [1] 804

Yes. The sample size is large enough for the CLT to apply, but not too large that independence no longer holds. Randomness is assumed.


On your own

The question of atheism was asked by WIN-Gallup International in a similar survey that was conducted in 2005. (We assume here that sample sizes have remained the same.) Table 4 on page 13 of the report summarizes survey results from 2005 and 2012 for 39 countries.

Spain

## Single proportion -- success: atheist 
## Summary statistics:

## p_hat = 0.09 ;  n =  1145 
## Check conditions: number of successes = 103 ; number of failures = 1042 
## Standard error = 0.0085 
## 95 % Confidence interval = ( 0.0734 , 0.1065 )
## [1] 0.0166
## Single proportion -- success: atheist 
## Summary statistics:

## p_hat = 0.1003 ;  n =  1146 
## Check conditions: number of successes = 115 ; number of failures = 1031 
## Standard error = 0.0089 
## 95 % Confidence interval = ( 0.083 , 0.1177 )

The inference function gives the 95 % Confidence interval of Spain’s level of atheism in 2012 as ( 0.0734 , 0.1065 ).

In 2005, the 95 % Confidence interval was ( 0.083 , 0.1177 ).

The two ranges overlap from 0.083 to 0.1065.

Due to the significant overlap there is not sufficient evidence that Spain’s religiosity has changed.

United States

**b.** Is there convincing evidence that the United States has seen a
change in its atheism index between 2005 and 2012?
## Single proportion -- success: atheist 
## Summary statistics:

## p_hat = 0.01 ;  n =  1002 
## Check conditions: number of successes = 10 ; number of failures = 992 
## Standard error = 0.0031 
## 95 % Confidence interval = ( 0.0038 , 0.0161 )

95 % Confidence interval (2012) = ( 0.0364 , 0.0634 )

95 % Confidence interval (2005) = ( 0.0038 , 0.0161 )

These confidence intervals do not intersect, suggesting that there was been a qualitative change in the religiosity of Americans.

A Type 1 error occurs when the null hypothesis is incorrectly rejected. If the atheism index is unchanged, it is still possible that we would see confidence intervals that do not overlap, though they should. This would likely occur less than 2.5% of the time by chance alone, with upper bounds failing to cross lower bounds.

## [1] 9604

A sample size of 9604 residents would be required to ensure the 1% Margin of Error. This is calculated conservatively after maximizing p(1-p), with p of 50%.