Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:50:49+00:00 2026-05-26T09:50:49+00:00

I have a data set on N numbers that I want to test for

  • 0

I have a data set on N numbers that I want to test for normality.
I know scipy.stats has a kstest function
but there are no examples on how to use it and how to interpret the results.
Is anyone here familiar with it that can give me some advice?

According to the documentation, using kstest returns two numbers, the KS test statistic D and the p-value.
If the p-value is greater than the significance level (say 5%), then we cannot reject the hypothesis that the data come from the given distribution.

When I do a test run by drawing 10000 samples from a normal distribution and testing for gaussianity:

import numpy as np
from scipy.stats import kstest

mu,sigma = 0.07, 0.89
kstest(np.random.normal(mu,sigma,10000),'norm')

I get the following output:

(0.04957880905196102, 8.9249710700788814e-22)

The p-value is less than 5% which means that we can reject the hypothesis that the data are normally distributed. But the samples were drawn from a normal distribution!

Can someone understand and explain to me the discrepancy here?

(Does testing for normality assume mu = 0 and sigma = 1? If so, how can I test that my data are gaussianly distributed but with a different mu and sigma?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:50:49+00:00Added an answer on May 26, 2026 at 9:50 am

    Your data was generated with mu=0.07 and sigma=0.89.
    You are testing this data against a normal distribution with mean 0 and standard deviation of 1.

    The null hypothesis (H0) is that the distribution of which your data is a sample is equal to the standard normal distribution with mean 0, std deviation 1.

    The small p-value is indicating that a test statistic as large as D would be expected with probability p-value.

    In other words, (with p-value ~8.9e-22) it is highly unlikely that H0 is true.

    That is reasonable, since the means and std deviations don’t match.

    Compare your result with:

    In [22]: import numpy as np
    In [23]: import scipy.stats as stats
    In [24]: stats.kstest(np.random.normal(0,1,10000),'norm')
    Out[24]: (0.007038739782416259, 0.70477679457831155)
    

    To test your data is gaussian, you could shift and rescale it so it is normal with mean 0 and std deviation 1:

    data=np.random.normal(mu,sigma,10000)
    normed_data=(data-mu)/sigma
    print(stats.kstest(normed_data,'norm'))
    # (0.0085805670733036798, 0.45316245879609179)
    

    Warning: (many thanks to user333700 (aka scipy developer Josef Perktold)) If you don’t know mu and sigma, estimating the parameters makes the p-value invalid:

    import numpy as np
    import scipy.stats as stats
    
    mu = 0.3
    sigma = 5
    
    num_tests = 10**5
    num_rejects = 0
    alpha = 0.05
    for i in xrange(num_tests):
        data = np.random.normal(mu, sigma, 10000)
        # normed_data = (data - mu) / sigma    # this is okay
        # 4915/100000 = 0.05 rejects at rejection level 0.05 (as expected)
        normed_data = (data - data.mean()) / data.std()    # this is NOT okay
        # 20/100000 = 0.00 rejects at rejection level 0.05 (not expected)
        D, pval = stats.kstest(normed_data, 'norm')
        if pval < alpha:
            num_rejects += 1
    ratio = float(num_rejects) / num_tests
    print('{}/{} = {:.2f} rejects at rejection level {}'.format(
        num_rejects, num_tests, ratio, alpha))     
    

    prints

    20/100000 = 0.00 rejects at rejection level 0.05 (not expected)
    

    which shows that stats.kstest may not reject the expected number of null hypotheses
    if the sample is normalized using the sample’s mean and standard deviation

    normed_data = (data - data.mean()) / data.std()    # this is NOT okay
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
I have a data set that looks like this: 000 100 200 300 010
I have a data set with over 50,000 geocoded points (lat-long). Each point has
I have a data set that is around 700 rows with eight columns of
I have the following data set that I am trying to plot with ggplot2,
I have a PreferenceActivity that gets its data from a web service(Call forward Numbers,
I have a data set whose elements are displayed as rows in a DataGrid.
I have a data set which consists of an ID and a matrix (n
Interpolating Large Datasets I have a large data set of about 0.5million records representing
I want to use redis for my game's leaderboard data and I have seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.