R
R
Rudolf Nemov2020-11-15 13:08:32
Python
Rudolf Nemov, 2020-11-15 13:08:32

How to find Student's t-test using python?

Sorry for the imprecisely worded question.

The teacher suggests finding the Student's t-test using this formula:

5fb0fd626cdc5416693839.png

However, I noticed that I get different values ​​compared to the scipy.stats.ttest_ind method -1.6127911643120085

- my answer
is -1.6123875817242772 - the answer received through ttest_ind(ctrl, test, equal_var =False)
-1.6126205013707797 - response received via ttest_ind(ctrl, test, equal_var=True)

My function now:

ctrl = df[df['group'] == 'A']['converted'] # pandas Series, control group
test = df[df['group'] == 'B']['converted'] # pandas Series, test group

t = (np.mean(ctrl) - np.mean(test)) / np.sqrt(
    ((np.std(ctrl) ** 2) / ctrl.size) + ((np.std(test) ** 2) / test.size )
)


Please tell me if I made some mistake or the difference in values ​​is due to something else?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2020-11-15
@rudieduddie

I don't know what sample you have, but just in case, I would calculate the standard deviation by setting np.std (data, ddof = 1 ).
In my opinion, the correct option is using ttest_ind(ctrl, test, equal_var=False ). I would compare with him.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question