Generation

generate functionFri, 17 Mar 2023

Create a Python function calculating the confidence interval for the mean value if you know - the sample size (n); - the mean value of the sample (mean); - standard deviation (sig); - level of confidence (conf). Import necessary libraries. In function return specify the length of the resulting confidence interval (the difference between the right and left ends), rounded to integers. import numpy as np from scipy import stats def seed(seed): np.random.seed(seed) n = np.random.choice(range(10,26)) mean = np.random.choice(range(120,141)) sig = np.random.choice(range(10,21)) conf = np.random.choice([0.90, 0.95, 0.98, 0.99, 0.999]) return n, mean, sig, conf def interval(n, mean, sig, conf): h = return print(interval(*seed(12))) print(interval(*seed(45))) print(interval(*seed(7))) The result of the function should be three values: 12, 28, 21

import numpy as np from scipy import stats def seed(seed): np.random.seed(seed) n = np.random.choice(range(10,26)) mean = np.random.choice(range(120,141)) sig = np.random.choice(range(10,21)) conf = np.random.choice([0.90, 0.95, 0.98, 0.99, 0.999]) return n, mean, sig, conf def interval(n, mean, sig, conf): h = sig * stats.t.ppf((1+conf)/2, n-1) / np.sqrt(n) return np.round(h) print(interval(*seed(12))) print(interval(*seed(45))) print(interval(*seed(7))) The result of the function should be three values: 12, 28, 21

Questions about programming?Chat with your personal AI assistant