Rowan-Classes/5th-Semester-Fall-2023/Prob-and-Stat-for-ECEs/Homework/Homework-05.md
2024-02-22 14:23:12 -05:00

209 lines
7.6 KiB
Markdown

# Homework 5 - Aidan Sharpe
## 1
The finished inside diameter of a piston ring is normally distributed with a mean, $\mu = 10$[cm], and a standard deviation, $\sigma = 0.03$[cm].
### a)
What is the probability that the inside diameter exceeds 10.04[cm]?
$$Z = {10.04 - 10 \over 0.03} = {4 \over 3}$$
```ipython
>>> from scipy.stats import norm
>>> z = (10.04 - 10) / 0.03
>>> 1 - norm.cdf(z)
0.09121121972587254
```
$$P(X > 10.04) = 0.0912$$
### b)
What is the probability that a piston ring will have an inside diameter between 9.98[cm] and 10.02[cm]?
$$Z_1 = {9.98 - 10 \over 0.03}$$
$$Z_2 = {10.02 - 10 \over 0.03}$$
```python
>>> from scipy.stats import norm
>>> z1 = (9.98 - 10) / 0.03
>>> z2 = (10.02 - 10) / 0.03
>>> norm.cdf(z2) - norm.cdf(z1)
0.49501492490614524
```
$$P(9.98 < X < 10.02) = 0.4950$$
### c)
What is the probability that a piston ring will have an inside diameter of less than 10[cm]?
By the definition of a normal distribution:
$$P(X < \mu) = 0.5$$
## 2
A research engineer for a tire manufacturer is investigating tire life for a new rubber compound and has built 20 tires and tested them to end-of-life in a road test. The sample mean is $\bar{x} = 60139.7$[km] and the standard deviation, $\sigma = 3645.94$[km]. Calculate a 99% confidence interval for the mean life of all such tires.
For a 99% confidence interval, $\alpha = 0.01$, and the interval is given by:
$$\bar{x} \pm z_{\alpha \over 2} {\sigma \over \sqrt{n}}$$
```python
>>> from scipy.stats import norm
>>> a = 0.01
>>> z_a2 = norm.ppf(1 - (a/2))
>>> x_bar = 60139.7
>>> stddev = 3645.94
>>> x_bar + z_a2 * stddev / n**(1/2)
62239.66278858252
>>> x_bar - z_a2 * stddev / n**(1/2)
58039.73721141747
```
We are 99% certain that the mean life of a tire made with this rubber compound is between 62239.7[km] and 58039.7[km].
## 3
A sample of $n = 25$ joint specimens of a particular type gave a sample mean proportional limit stress of $\bar{x} = 8.6$[MPa] and a sample standard deviation of $s = 0.81$[MPa]. Construct and interpret in context a 95% confidence interval for the true average proportional limit stress of all such joints. Note that the population standard deviation is not known here. Be sure to use the correct confidence interval formulation.
For a 95% confidence interval, $\alpha = 0.05$, and the interval is given by:
$$\bar{x} \pm t^* {s \over \sqrt{n}}$$
```python
>>> from scipy.stats import t
>>> n = 25
>>> x_bar = 8.6E6
>>> s = 0.81E6
>>> a = 0.05
>>> t_star = t.ppf(1 - (a/2), n)
>>> x_bar + t_star * s / n**(1/2)
8933645.245546034
>>> x_bar - t_star * s / n**(1/2)
8266354.754453966
```
We are 95% confident that the mean proportional limit stress for this type of joint specimen is between 8.2[MPa] and 8.9[MPa].
## 4
A sample of 45 pieces of laminate used in the manufacture of circuit boards was selected and the amount of warpage, in inches, under particular conditions was determined for each piece, resulting in a sample mean warpage of $\bar{x} = 0.0631$[in] and a sample standard deviation of $s = 0.0072$[in].
### a)
Construct and interpret in context a 99% confidence interval for the average amount of warpage in all such pieces of laminate.
```python
>>> from scipy.stats import t
>>> x_bar = 0.0631
>>> s = 0.0072
>>> a = 0.01
>>> n = 45
>>> t_star = t.ppf(1-a/2, n)
>>> x_bar + t_star * s / n**(1/2)
0.06598676556860165
>>> x_bar - t_star * s / n**(1/2)
0.06021323443139835
```
We are 99% certain that the average amount of warpage in all pieces of this type of laminate is between 0.0602 inches and 0.0660 inches.
### b)
Construct and interpret in context a 90% confidence interval for the average amount of warpage in all such pieces of laminate.
```python
>>> from scipy.stats import t
>>> x_bar = 0.0631
>>> s = 0.0072
>>> n = 45
>>> a = 0.1
>>> t_star = t.ppf(1-a/2, n)
>>> x_bar + t_star * s / n**(1/2)
0.06490255062920108
>>> x_bar - t_star * s / n**(1/2)
0.06129744937079893
```
We are 90% certain that the average amount of warpage in all pieces of this type of laminate is between 0.0613 inches and 0.0649 inches.
### c)
Which interval is wider and why?
The only ways to increase confidence are by increasing sample size and by increasing the width of the confidence interval. A smaller confidence interval inherintly has a larger uncertainty associated with it. For this reason, the 90% confidence interval is smaller than the 99% confidence interval.
## 5
For this problem, use the code labeled problem 6 in the file hw 5 code on Canvas. You will explore the width of a confidence interval as the sample size increases. Suppose we are interested in estimating some population parameter $\mu$. We will fix the population parameter to be $\mu = 75$. Of course, in practice we would not know $\mu$, otherwise we would not need to estimate it. Assume the population standard deviation is $\sigma = 13$.
**To find the width of an interval, subtract the lower bound from the upper bound**
```python
>>> from scipy.stats import norm
>>> import numpy as np
>>> def sample_mean(sample_size):
... sample = np.random.chisquare(df=75, size=samplesize)
... return np.mean(sample)
```
### a)
Let $n=10$. Run `sample_mean(10)` and record the value of $\bar{x}$. Use $\bar{x}$ to construct a 95% confidence interval for $\mu$.
```python
>>> n = 10
>>> x_bar = sample_mean(n)
>>> x_bar # Print out the sample mean for n=10
73.32164347142393
>>> a = 0.05
>>> stddev = 13
>>> z_a2 = norm.ppf(1 - a/2)
>>> x_bar + z_a2 * stddev / n**(1/2) # Find the upper bound for the CI
81.37897889138323
>>> x_bar - z_a2 * stddev / n**(1/2) # Find the lower bound for the CI
65.26430805146462
```
The 95% confidence interval for $n=10$ is (65.26, 81.38).
### b)
Do the same for $n=50$.
```python
>>> n = 50
>>> x_bar = sample_mean(n)
>>> x_bar # Print out the sample mean for n=50
76.17226231360712
>>> a = 0.05
>>> stddev = 13
>>> z_a2 = norm.ppf(1 - a/2)
>>> x_bar + z_a2 * stddev / n**(1/2) # Find the upper bound for the CI
79.77561225691628
>>> x_bar - z_a2 * stddev / n**(1/2) # Find the lower bound for the CI
72.56891237029797
```
The 95% confidence interval for $n=50$ is (72.57, 79.78).
### c)
Do the same for $n=500$.
```python
>>> n=500
>>> x_bar = sample_mean(n)
>>> x_bar # Print out the sample mean for n=500
74.93800434978642
>>> x_bar + z_a2 * stddev / n**(1/2) # Find the upper bound for the CI
76.07748365253597
>>> x_bar - z_a2 * stddev / n**(1/2) # Find the lower bound for the CI
73.79852504703688
```
The 95% confidence interval for $n=500$ is (73.80, 76.08).
### d)
Do the same for $n=5000$.
```python
>>> n=5000
>>> x_bar = sample_mean(n)
>>> x_bar # Print out the sample mean for n=5000
74.92683635507494
>>> x_bar + z_a2 * stddev / n**(1/2) # Find the upper bound for the CI
75.28717134940585
>>> x_bar - z_a2 * stddev / n**(1/2) # Find the lower bound for the CI
74.56650136074403
```
The 95% confidence interval for $n=5000$ is (74.57, 75.29).
### e)
Do the same for $n=50000$.
```python
>>> n=50000
>>> x_bar = sample_mean(n)
>>> x_bar # Print out the sample mean for n=50000
75.03170012357572
>>> x_bar + z_a2 * stddev / n**(1/2) # Find the upper bound for the CI
75.14564805385068
>>> x_bar - z_a2 * stddev / n**(1/2) # Find the lower bound for the CI
74.91775219330076
```
The 95% confidence interval for $n=50000$ is (74.92, 75.15).
### f)
What do you notice abou the width of the confidence interval as the sample size increases?
As the sample size increases, the width of the confidence interval decreases quickly at first, but quickly yields diminishing returns.