Question

In 1181:from scipy import stats fron rath import sgrt Confidence Interval For a sample with size large enough, by central limit theorem we can assume its mean follows normal distribution. And if we also know the standard deviation of the population, we are able to calculate a confidence interval to estimate the population mean. Problem 1 A confidence interval is usually given by sample mean m plus and minus a margin of error r The contidence interval is larger (less precisel tor large contidence level, and smaller (more precise) for small contidence level. For this problam, you are askad to write a function Error that calculates the margin of error r given sample size , confidence level p and standard deviation of Im-rm +r the population s. Code: Error (40,0.95,20) Error (40,0.95, 10) Output 6.1979503230456140 3.0989751615228074 In 1191:modify this cell def Error (n,D,8) inputs: sample size n, confidence level p and standard deviations output: margin of error r YOUR CODE HERE in [47]1 Check function assert aba(Error(60,0.9,20)-.2469938027546128) <10+-5 assert aba(Error(60,0.9,10)-2.123496901377306) 10+-5 # AUTOGRADER TEST-DO NOT REMOVE Problem 2 For this problem, you are asked to write a function confidence that calculates the confidence level deviation of the population s given sample size n, margin of error , and standard Code: Confidenc40, 6,20) Confidence40,8,20) Output 0.98858796361399826 in 148] ! # modify this coll dot confidenc이 n , r·s) : # inputs: sample sizo ne margin of error r, and st ndard deviation s # output: conf įdnce level r # YOUR CODE HERE In [49]: # Check Function assert abs (Confidence (60,5,20)-0.94719248858388649) 10^*-5 assert abs (Confidence (60,6,20)-0-97986324844965367) 10-5 AUTOGRADER TEST-DO NOT REMOVE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

from scipy import stats
from math import sqrt

Problem 1:

def Error(n, p, s):
z = stats.norm.ppf(1-(1-p)/2)
moe = z * s / sqrt(n)
return moe

Problem 2:

def Confidence(n, r, s):
z = r * sqrt(n) / s
v = stats.norm.cdf(z)
p = 1 - 2 * (1 - v)
return p

Add a comment
Know the answer?
Add Answer to:
In 1181:from scipy import stats fron rath import sgrt Confidence Interval For a sample with size...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT