Commit f8aeaaec by Liwen Huang

Upload New File

parent 9dfd7f34
 %% Cell type:markdown id: tags: ## Question 3 A correlation is a statistical relationship between two variables. If we wanted to know if vaccines work, we might look at the correlation between the use of the vaccine and whether it results in prevention of the infection or disease [1]. In this question, you are to see if there is a correlation between having had the chicken pox and the number of chickenpox vaccine doses given (varicella). Some notes on interpreting the answer. The `had_chickenpox_column` is either 1 (for yes) or 2 (for no), and the `num_chickenpox_vaccine_column` is the number of doses a child has been given of the varicella vaccine. A positive correlation (e.g., `corr > 0`) means that an increase in `had_chickenpox_column` (which means more no's) would also increase the values of `num_chickenpox_vaccine_column` (which means more doses of vaccine). If there is a negative correlation (e.g., `corr < 0`), it indicates that having had chickenpox is related to an increase in the number of vaccine doses. Also, `pval` is the probability that we observe a correlation between `had_chickenpox_column` and `num_chickenpox_vaccine_column` which is greater than or equal to a particular value occurred by chance. A small `pval` means that the observed correlation is highly unlikely to occur by chance. In this case, `pval` should be very small (will end in e-18 indicating a very small number). [1] This isn't really the full picture, since we are not looking at when the dose was given. It's possible that children had chickenpox and then their parents went to get them the vaccine. Does this dataset have the data we would need to investigate the timing of the dose? %% Cell type:code id: tags: ``` python def corr_chickenpox(): import scipy.stats as stats import numpy as np import pandas as pd # this is just an example dataframe df=pd.DataFrame({"had_chickenpox_column":np.random.randint(1,3,size=(100)), "num_chickenpox_vaccine_column":np.random.randint(0,6,size=(100))}) # here is some stub code to actually run the correlation corr, pval=stats.pearsonr(df["had_chickenpox_column"],df["num_chickenpox_vaccine_column"]) # just return the correlation #return corr # YOUR CODE HERE raise NotImplementedError() ``` %% Cell type:code id: tags: ``` python import numpy as np import pandas as pd import scipy.stats as stats df = pd.read_csv('datasets/NISPUF17.csv', index_col = 0) df.head() ``` %%%% Output: execute_result SEQNUMC SEQNUMHH PDAT PROVWT_D RDDWT_D STRATUM YEAR AGECPOXR \ 1 128521 12852 2 NaN 235.916956 1031 2017 NaN 2 10741 1074 2 NaN 957.353840 1068 2017 NaN 3 220011 22001 2 NaN 189.611299 1050 2017 NaN 4 86131 8613 1 675.430817 333.447418 1040 2017 NaN 5 227141 22714 1 482.617748 278.768063 1008 2017 NaN HAD_CPOX AGEGRP ... XVRCTY2 XVRCTY3 XVRCTY4 XVRCTY5 XVRCTY6 \ 1 2 1 ... NaN NaN NaN 2 2 1 ... NaN NaN NaN 3 2 3 ... NaN NaN NaN 4 2 1 ... NaN NaN NaN 5 2 1 ... NaN NaN NaN XVRCTY7 XVRCTY8 XVRCTY9 INS_STAT2_I INS_BREAK_I 1 NaN NaN NaN NaN NaN 2 NaN NaN NaN NaN NaN 3 NaN NaN NaN NaN NaN 4 NaN NaN NaN 1.0 2.0 5 NaN NaN NaN 2.0 1.0 [5 rows x 453 columns] %% Cell type:code id: tags: ``` python df = df[df['HAD_CPOX'].lt(3)].loc[:,['HAD_CPOX','P_NUMVRC']].dropna() df ``` %%%% Output: execute_result HAD_CPOX P_NUMVRC 4 2 1.0 5 2 0.0 7 2 1.0 8 2 0.0 9 1 0.0 ... ... ... 28447 2 1.0 28448 2 1.0 28450 2 1.0 28453 2 1.0 28455 2 1.0 [15286 rows x 2 columns] %% Cell type:code id: tags: ``` python df.columns = ['had_chicken_col','num_vaccine_col'] corr, pval = stats.pearsonr(df["had_chicken_col"],df["num_vaccine_col"]) corr ``` %%%% Output: execute_result 0.07044873460147984 %% Cell type:code id: tags: ``` python ```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment