I would like to use the "calc" package's utpt function to compute a confidence interval of a series of numbers in a calc vector.

Currently, I'm stuck at the very beginning, with a calc buffer that looks like this:

1:  [10, 10, 11, 10, 10, 11, 10, 10, 9, 10, 10, 11, 9]

The resulting 99th percentile confidence interval in this case might be something like [9.2, 11.1].

The documentation for utpt says:

The ‘utpt(t,v)’ function uses the Student’s “t” distribution with ‘v’ degrees of freedom. It is the probability that a t-distributed random variable will be greater than ‘t’. (Note: This computes the distribution function ‘A(t|v)’ where ‘A(0|v) = 1’ and ‘A(inf|v) -> 0’.

Right at the start, I'm not sure how to pass the two values to utpt within a calc *Calculator* buffer. Is it possible to call it while in RPN mode?

More broadly, I am trying to port this Python to Emacs Lisp:

import statistics
import scipy.stats as st

def ConfidenceInterval99(a):
    # Return the 99% confidence interval for the population mean
    # weight.
    mean = statistics.mean(a)
    scale = st.sem(a)  # Compute standard error of the mean.
    if len(a) < 30:
        return st.t.interval(confidence=0.99, df=len(a) - 1, loc=mean, scale=scale)
        return st.norm.interval(confidence=0.99, loc=mean, scale=scale)

Where the st.t.interval function is documented here.

...but at this point I'll settle for a description of how to call utpt interactively from the *Calculator* buffer.

  • You push v, then you push t and then you say k T. E.g. for 2 degreess of freedom and a t value of 5, you push 2, then you push 5 and then k T gives you 0.10193947883.
    – NickD
    Commented Oct 27, 2022 at 3:12
  • More generally, any time you want to use a multi–argument function you need to first arrange for the arguments to be on the stack (by pushing them, swapping them, rotating the stack, etc). When you call the function it will pop its arguments off of the stack, consuming them.
    – db48x
    Commented Oct 27, 2022 at 3:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.