+1 vote
in Programming Languages by (74.7k points)

The following code gives the error: "TypeError: rv_generic.interval() missing 1 required positional argument: 'confidence'"

>>> a=[10,12,5,8,19]

>>> st.t.interval(alpha=0.95, df=len(a)-1, loc=np.mean(a), scale=st.sem(a))

How to fix this error?

1 Answer

+3 votes
by (84.8k points)
selected by
 
Best answer

The format of the interval() function is as follows:

interval(confidence, df, loc=0, scale=1)

There is no 'alpha' argument in the function. The 'confidence' argument is used as the first positional argument instead of 'alpha'. So, to compute 95% confidence interval, just put 0.95 as the first argument and it should work.

Here is the modified code:

>>> a=[10,12,5,8,19]

>>> st.t.interval(0.95, len(a)-1, loc=np.mean(a), scale=st.sem(a))

(4.265024352083662, 17.334975647916337)


...