-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Problem 1: \n", | ||
"\n", | ||
"#### Blood glucose levels for obese patients have a mean of 100 with a standard deviation of 15. A researcher thinks that a diet high in raw cornstarch will have a positive effect on blood glucose levels. A sample of 36 patients who have tried the raw cornstarch diet have a mean glucose level of 108. Test the hypothesis that the raw cornstarch had an effect or not.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Solution:\n", | ||
"\n", | ||
"##### H0:μ=100 null hypothesis\n", | ||
"##### H1:μ≠100 Alternate hypothesis\n", | ||
"\n", | ||
"##### we have sample size > 30 and population standard deviation is given.so,we will use Z-statistics. let’s assume significance level (α)as 5% (0.05)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Z Score : 3.2\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import math\n", | ||
"sample_size = 36\n", | ||
"sample_mean = 108\n", | ||
"population_mean = 100\n", | ||
"population_std = 15\n", | ||
"z = (sample_mean - population_mean) / (population_std /math.sqrt(sample_size))\n", | ||
"print(\"Z Score :\",z)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"##### by looking at z- table the p-value associated with 3.20 is 0.9993 \n", | ||
"##### The probability of having mean less than 108 is 0.9993 and more than or equals to 108 is (1-0.9993)=0.0007.\n", | ||
"##### Since the probability of having mean glucose level more than or equals to 108 is 0.0007 which is less than 0.05 \n", | ||
"##### so we will reject the Null hypothesis i.e. there is raw cornstarch effect." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Problem 2:\n", | ||
"\n", | ||
"###### In one state, 52% of the voters are Republicans, and 48% are Democrats. In a second state, 47% of the voters are Republicans, and 53% are Democrats. Suppose a simple random sample of 100 voters are surveyed from each state. What is the probability that the survey will show a greater percentage of Republican voters in the second state than in the first state?\n", | ||
"\n", | ||
"### Solution:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"μ : 0.050000000000000044 \n", | ||
"Std : 0.07061869440877536\n", | ||
"Z_score(p1,p2) : -0.7080278164104213\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#let\n", | ||
"#P1 = the proportion of Republican voters in the first state\n", | ||
"#P2 = the proportion of Republican voters in the second state\n", | ||
"#Q1 = the proportion of Democrats voters in the first state\n", | ||
"#Q2 = the proportion of Democrats voters in the second state\n", | ||
"#p1 = the proportion of Republican voters in the sample from the first state\n", | ||
"#p2 = the proportion of Republican voters in the sample from the second state. \n", | ||
"\n", | ||
"#The number of voters sampled from the first state (n1) = 100\n", | ||
"n1 = 100\n", | ||
"#The number of voters sampled from the second state (n2) = 100.\n", | ||
"n2 = 100\n", | ||
"\n", | ||
"P1 = 0.52\n", | ||
"Q1 = 0.48\n", | ||
"P2 = 0.47\n", | ||
"Q2 = 0.53\n", | ||
"\n", | ||
"\n", | ||
"#The mean of the difference in sample proportions .i.e Expected Value E[p1 -p2] = P1 - P2 = μ\n", | ||
"μ = P1 - P2\n", | ||
"\n", | ||
"#The standard deviation of the difference (std)\n", | ||
"std = math.sqrt(((P1 * Q1 ) / n1) + ((P2 * Q2) /n2))\n", | ||
"print(\"μ : \",μ,\"\\nStd : \",std)\n", | ||
"\n", | ||
"#The problem requires us to find the probability that p1 is less than p2. \n", | ||
"#This is equivalent to finding the probability that p1 - p2 < 0. \n", | ||
"x = 0\n", | ||
"#To find this probability, we need to transform the random variable (p1 - p2) into a z-score. \n", | ||
"\n", | ||
"Z = ( x - μ)/std\n", | ||
"print(\"Z_score(p1,p2) : \",Z)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"##### From Z table we find that the probability of a z-score being -0.7082 or less is 0.24.\n", | ||
"\n", | ||
"##### Therefore, the probability that the survey will show a greater percentage of Republican voters in the second state than in the first state is 0.24." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Problem 3:\n", | ||
"\n", | ||
"#### You take the SAT and score 1100. The mean score for the SAT is 1026 and the standard deviation is 209. How well did you score on the test compared to the average test taker?\n", | ||
"\n", | ||
"### Solution:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Z Score : 0.35406698564593303\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"x = 1100 \n", | ||
"μ= 1026 # Population Mean\n", | ||
"std = 209 #population standard deviation\n", | ||
"z = ( x - μ)/std\n", | ||
"print(\"Z Score : \",z)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### from Z-table the z-value is 0.6368.So the test taker performed 63.68% better than average test taker." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |