Show Non-Central F-Distribution in Statistics using Python

In statistics, the Non-Central F-Distribution is a probability distribution used for analyzing variance in data when the null hypothesis is false. Unlike the central F-distribution, it includes a non-centrality parameter that shifts the distribution, making it useful for power analysis and hypothesis testing.

Understanding the Non-Central F-Distribution

The Non-Central F-Distribution extends the central F-distribution by adding a non-centrality parameter (?). This distribution is characterized by three parameters:

  • Numerator degrees of freedom (dfn)
  • Denominator degrees of freedom (dfd)
  • Non-centrality parameter (nc)

The non-centrality parameter determines how much the distribution deviates from the central F-distribution. When nc = 0, it reduces to the standard F-distribution.

F-statistic Density Non-Central F-Distribution Central F (nc=0) Non-Central F (nc>0)

Plotting Non-Central F-Distribution

We use scipy.stats.ncf to work with the non-central F-distribution. The following example shows both PDF and CDF ?

import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt

# Define parameters
dfn = 5  # numerator degrees of freedom
dfd = 10  # denominator degrees of freedom  
nc = 2   # non-centrality parameter

# Generate x values
x = np.linspace(0.1, 8, 1000)

# Calculate PDF and CDF
pdf = stats.ncf.pdf(x, dfn, dfd, nc)
cdf = stats.ncf.cdf(x, dfn, dfd, nc)

# Create subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))

# Plot PDF
ax1.plot(x, pdf, 'b-', linewidth=2, label=f'nc={nc}')
ax1.set_xlabel('x')
ax1.set_ylabel('Probability Density')
ax1.set_title('Non-Central F-Distribution (PDF)')
ax1.grid(True, alpha=0.3)
ax1.legend()

# Plot CDF
ax2.plot(x, cdf, 'r-', linewidth=2, label=f'nc={nc}')
ax2.set_xlabel('x')
ax2.set_ylabel('Cumulative Probability')
ax2.set_title('Non-Central F-Distribution (CDF)')
ax2.grid(True, alpha=0.3)
ax2.legend()

plt.tight_layout()
plt.show()
[Two plots displayed side by side showing the PDF and CDF of the non-central F-distribution]

Comparing Different Non-Centrality Parameters

Let's visualize how the non-centrality parameter affects the distribution shape ?

import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt

# Parameters
dfn, dfd = 5, 10
nc_values = [0, 1, 2, 5]
x = np.linspace(0.1, 10, 1000)

plt.figure(figsize=(10, 6))

for nc in nc_values:
    pdf = stats.ncf.pdf(x, dfn, dfd, nc)
    label = f'nc = {nc}' + (' (Central F)' if nc == 0 else '')
    plt.plot(x, pdf, linewidth=2, label=label)

plt.xlabel('x')
plt.ylabel('Probability Density')
plt.title('Effect of Non-Centrality Parameter on F-Distribution')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()
[Plot showing multiple curves with different non-centrality parameters]

Key Properties

Property Description Formula/Value
Mean Expected value (dfd × (dfn + nc)) / (dfn × (dfd - 2))
Mode Peak location Shifts right as nc increases
Special Case When nc = 0 Becomes central F-distribution

Practical Applications

The non-central F-distribution is commonly used in:

  • Power Analysis Determining sample sizes for ANOVA
  • Hypothesis Testing When the null hypothesis is false
  • Confidence Intervals For variance ratios in regression

Conclusion

The non-central F-distribution extends the central F-distribution with a non-centrality parameter, making it essential for power analysis and hypothesis testing. Python's scipy.stats.ncf provides comprehensive tools for working with this distribution.

Updated on: 2026-03-27T15:44:00+05:30

279 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements