4

I couldn't understand how to properly use t.ppf, could someone please explain it to me?

I have to use this information

  • scipy.stats.t
  • scipy.stats
  • a mean of 100
  • a standard deviation of 0.39
  • N = 851 (851 samples)

When I'm asked to calculate the (95%) margin of error using t.ppf() will the code look like below?

cutoff1 = t.ppf(0.05,100,0.36,850) 

Can somebody help me, please?

2 Answers 2

12

According to the reference docs, the arguments to t.ppf are q, df, loc, and scale. The df argument is degrees of freedom, which is usually the sample size minus 1 for a single population sampling problem. Since ppf calculates the inverse cumulative distribution function, by definition a result of x for a given q-value and df means P{T <= x} = q, i.e, there is probability q of getting outcomes less than or equal to x from a T distribution with the given loc and scale. The loc (mean) and scale (standard deviation) arguments are optional, and default to 0 and 1, respectively.

To get a 95% margin of error, you want 5% of the probability to be in the tails of the distribution. This is usually done symmetrically so that 2.5% is in each tail, so you would use q values of 0.025 and 0.975 for the lower and upper cutoff points respectively. For your particular problem, the code would look something like:

from scipy.stats import t

n = 851
mean = 100
std_dev = 0.39

lower_cutoff = t.ppf(0.025, n - 1, loc = mean, scale = std_dev)  # =>  99.23452406698323
upper_cutoff = t.ppf(0.975, n - 1, loc = mean, scale = std_dev)  # => 100.76547593301677
6
  • 95%CI is mentioned to be mean+/-1.96*SE where SE = SD/sqrt(N) ; See here: amsi.org.au/ESA_Senior_Years/SeniorTopic4/4h/… ; By this formula, one get these values: 99.973796 and 100.02620329 ; Why are these values so much different from values obtained in this answer?
    – rnso
    Jan 13, 2022 at 13:35
  • Actually values obtained in the answer (99.234 and 100.765) are obtained with formula of mean+/-1.96*SE if SE=SD/1 i.e. when N=1 (so that sqrt(1) is 1)
    – rnso
    Jan 13, 2022 at 14:20
  • 1
    @rnso The question explicitly asked about t.ppf rather than t.interval, so I assumed they were asking for percentiles under the assumption of normality with known mean but unknown variance, and not about a CI. The difference is a factor of sqrt(n) for the CI half-width. t.interval(0.05, n - 1, loc = mean, scale = std_dev) yields a CI of (99.97553713440418, 100.02446286559582), in line with your comment. Note that using 1.96 assumes the t distribution has asymptotically converged to normal -- not a bad assumption for n = 851 -- but only gives three significant digits.
    – pjs
    Jan 13, 2022 at 14:59
  • Very well explained. Thanks.
    – rnso
    Jan 13, 2022 at 16:43
  • The df argument is degrees of freedom, which is usually the sample size minus 1 for a single population sampling problem. Why minus 1?
    – NoName
    Jul 19, 2022 at 16:47
0

I'm almost certain you have to use standard error instead, which is std/sqrt(n)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.