<jupyter_start><jupyter_text>Exercise 8. Selection characteristics  <NAME>  Other selected continuous distributions  $\chi^2$ - Chi-square distribution(Pearns distribution) - Use: when estimating the standard deviation(using sampling) - Has a single parameter - the number of degrees of freedom - $\frac{S^2}{\sigma^2}(n-1) \sim \chi^2_{n-1}$ - $S$ is the sample standard deviation<jupyter_code>n =  5 # number of degrees of freedom
x = seq(from = 0, to = 30, by = 0.01) # x-axis
fx = dchisq(x = x, df = n) # chi-quad probability density. distribution

plot(x, fx, type='l')
Fx = pchisq(q = x, df = n) # distrib. fce. chi-kvad. distribution

plot(x, Fx, type='l')<jupyter_output><empty_output><jupyter_text>$t$ - Student's distribution - Application: when estimating the mean without exact knowledge of variance(sampling only) - $\frac{\bar X - \mu}{S}\sqrt{n} \sim t_{n-1} $ - $\bar X$ is the sample average - $S$ is the sample standard deviation - converges to a normalized normal distribution with increasing number of degrees of freedom<jupyter_code>n =  5 # number of degrees of freedom
x = seq(from = -3, to = 3, by = 0.01) # x-axis
fx = dt(x = x, df = n) # probability density of the student's distribution

plot(x, fx, type='l')

fnorm = dnorm(x, mean=0, sd=1)  # norm values. normal birth
lines(x, fnorm, col="red")      # to the last graph

Fx = pt(q = x, df = n) # probability density of the student's distribution

plot(x, Fx, type='l')

Fnorm = pnorm(x, mean=0, sd=1)  # norm values. normal birth
lines(x, Fnorm, col="red")      # to the last graph<jupyter_output><empty_output><jupyter_text>$F$ - Fisher-Snedecor distribution - Used to test stairs of scatter - $\frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \sim F_{n_1 - 1, n_2 - 1}$<jupyter_code>n = 5  # number of degrees of freedom selection. 1
m = 6  # number of degrees of freedom selection. 2
x = seq(from = 0, to = 10, by = 0.01) # x-axis
fx = df(x = x, df1 = n, df2 = m) # chi-quad probability density. distribution

plot(x, fx, type='l')
Fx = pf(q = x, df1 = n, df2 = m) # chi-quad probability density. distribution

plot(x, Fx, type='l')<jupyter_output><empty_output><jupyter_text>How does the average of the values from the normal distribution behave? The function **rnorm(n, mean, sd)** generates **n** values from the normal distribution with themeanvalue **mean** and the standard deviation **sd**.<jupyter_code>vel_nah_vyberu = 30
mu = 10
sigma = 3
nah_vyber = rnorm(n=vel_nah_vyberu, mean=mu, sd=sigma) 
nah_vyber
mean(nah_vyber)
sd(nah_vyber)<jupyter_output><empty_output><jupyter_text>Random variable: average of values<jupyter_code>poc_vyberu = 1000
prumery = numeric(poc_vyberu) # numeric produces vector 0
smer_odchylky = numeric(poc_vyberu)
for(i in 1:poc_vyberu){
  nah_vyber = rnorm(n=vel_nah_vyberu,mean=mu,sd=sigma)
  prumery[i] = mean(nah_vyber)
  smer_odchylky[i] = sd(nah_vyber)
}
hist(prumery)
qqnorm(prumery)
qqline(prumery)
mean(prumery)
sd(prumery)
sigma/sqrt(vel_nah_vyberu)<jupyter_output><empty_output><jupyter_text>How does the average of values from the uniform distribution behave? The function **runif(n, min, max)** generates **n** values from the uniform distribution U(**min, max**).<jupyter_code>vel_nah_vyberu = 30
a = 1
b = 7
nah_vyber=runif(n=vel_nah_vyberu, min=a, max=b)
# nah_vyber

hist(nah_vyber)
qqnorm(nah_vyber)
qqline(nah_vyber)
mu = (a+b)/2
mu
mean(nah_vyber)
sigma = sqrt((b-a)^2/12)
sigma
sd(nah_vyber)<jupyter_output><empty_output><jupyter_text>Random variable: average of values<jupyter_code>poc_vyberu = 1000
prumery = numeric(poc_vyberu)
smer_odchylky = numeric(poc_vyberu)
for(i in 1:poc_vyberu){
  nah_vyber = runif(n=vel_nah_vyberu, min=a, max=b)
  prumery[i] = mean(nah_vyber)
  smer_odchylky[i] = sd(nah_vyber)
}
hist(prumery)
qqnorm(prumery)
qqline(prumery)
mean(prumery)
sd(prumery)
sigma/sqrt(vel_nah_vyberu)<jupyter_output><empty_output><jupyter_text>Examples  Example 1. The load on an aircraft with 64 seats shall not exceed 6,000 kg. What is the probability that this value will be exceeded at full occupancy if the passenger mass has a mean value of 90 kg and a standard deviation of 10 kg?<jupyter_code># X... weight 64 passengers
# X~N(64 * 90; 64 * 100)
# P(X>6000)=1 - F(6000)

1 - pnorm(q=6000, mean=64*90, sd=sqrt(64*100))<jupyter_output><empty_output><jupyter_text>Example 2. The consignment contains 300 products of a certain type. It is known that the probability of making a defective product of this type is 0.04.  a) Estimate the probability that the absolute deviation of the proportion of defective products in the consignment from the probability of producing a defective product will be less than 1%.<jupyter_code># X=(p - π)/sqrt(π*(1 - π)) * sqrt(n) ∼ N(0, 1)
# P(-0.01/sqrt(π*(1 - π)) * sqrt(n)<X<0.01/sqrt(π*(1 - π)) * sqrt(n))
pi = 0.04
n = 300
bound = 0.01/sqrt(pi*(1-pi))*sqrt(n)
pnorm(q=bound, mean=0, sd=1) - pnorm(q=-bound, mean=0, sd=1)<jupyter_output><empty_output><jupyter_text>b) How will the result change if the shipment contains 3,000 products?<jupyter_code>n = 3000
bound = 0.01/sqrt(pi*(1-pi))*sqrt(n)
pnorm(q=bound, mean=0, sd=1) - pnorm(q=-bound, mean=0, sd=1)<jupyter_output><empty_output><jupyter_text>Example 3. Passengers regularly travel to and from public transport. It is known that the waiting time for the arrival of public transport ranges from 0 to 3 minutes. What is the probability that the total waiting time for an employee to arrive by public transport in 23 working days will be less than 80 minutes?<jupyter_code># Y... time of the i-th waiting for public transport
# y~R(0; 3)
# X... total waiting time in 23 days(round trip ⇒ 46 waiting)
# X~N(46 * EY; 46 * DY)
# P(X<80)

a = 0
b = 3
n = 46
EY = (a+b)/2
DY = (b-a)^2/12

pnorm(q=80, mean=n*EY, sd=sqrt(n*DY))<jupyter_output><empty_output><jupyter_text>Example 4. Assume that the average electricity consumption of households in a given city in January is 120 kWh and the standard deviation of consumption is 100 kWh. Determine the probability that the average consumption of 100 randomly selected households will be greater than 140 kWh.<jupyter_code># Xi... consumption of the i-th household
# X... average consumption of 100 households
# X~N(EXi; Dxi/n)
# P(X>140)

EXi = 120
DXi = 100^2
n = 100
1 - pnorm(q=140, mean=EXi, sd=sqrt(DXi/n))<jupyter_output><empty_output><jupyter_text>Example 5. The Acme Battery Company has developed a new type of mobile phone battery. On average, batteries last 60 minutes on a single charge. The standard deviation of this time is 4 minutes. Assume that the production department runs a quality control test after 6 months. They performed two random selections with a range of 10 batteries and in both found a standard deviation of battery life greater than 6 minutes. How likely were they to expect such a result?<jupyter_code># X=(n - 1) S ^ 2/σ ^ 2
# X ∼ χ_n-1
# P(S>6)=P(X>...)

n = 10
S_obs = 6
sigma = 4
X_obs = (n - 1)*S_obs^2/sigma^2

P_jedno_mereni = 1 - pchisq(q=X_obs, df=n-1)
P_jedno_mereni
P_jedno_mereni^2<jupyter_output><empty_output><jupyter_text>Example 6. The mortality tables show a probability of 0.99 that a 35-year-old man will live another year. The annual premium for this age group is CZK 2,000, in the event of death the insurance company will pay CZK 100,000. What is the probability that the profit of 500 insured men aged 35 will be at least CZK 500,000?(Solve in two ways - using the binomial distribution and using the binomial distribution approximation by the normal distribution.)<jupyter_code># X... number of men out of 500 who won't live to see another year
# X~Bi(500; 0.01)
# Z=500 · 2,000 - X · 100,000
# P(Z ≥ 500,000)=P(X ≤ 5)

pbinom(5, size=500, prob=0.01)
# X~Bi(500; 0.01)~N(500 * 0.01; 500 * 0.01*(1-0.01))
# P(X ≤ 5)~P(X<5.5)(continuity correction)

pnorm(5.5, mean=500*0.01, sd=sqrt(500*0.01*(1-0.01)))<jupyter_output><empty_output><jupyter_text>Example 7. Assume that approximately 60% of young men in the population have higher than recommended serum cholesterol levels. In a random selection of 200 young men, how likely will more than 120 of them have higher than recommended serum cholesterol levels?<jupyter_code># X... number of young men out of 200 with higher than recommended serum cholesterol levels
# X ∼ Bi(200; 0.6)
# P(X>120)=1 - P(X ≤ 120)

1 - pbinom(120, size=200, prob=0.6)
# X~N(200 * 0.6; 200 * 0.6(1-0.6)), ie X ≈ N(120; 48)
# 1 - P(X ≤ 120)~1 - P(X<120.5)(continuity correction)

1 - pnorm(120.5, mean=200*0.6, sd=sqrt(200*0.6*(1-0.6)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12419298039676019, 'fraction_numerical': 0.05141448526822397, 'mean_word_length': 4.883977900552487, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '241614', 'license': 'MIT', 'n_tokens_mistral': 3450, 'n_tokens_neox': 3081, 'n_words': 1033, 'path': 'support_files/en/.ipynb_checkpoints/cv8-checkpoint.ipynb', 'repo_name': 'Beremi/PS_eng_2022', 'size': '8525'}