Chi-square distribution and degrees of freedom

Chi-square test is the goodness of fit between a set (or vector) of observed values and expected values. Chi-square is one among other distributions.

Typical chi-square distribution can be plotted with following R code:

x = seq(0, 30, length.out = 200)
plot(x,dchisq(x=x, df=2), col=33, type = 'l', xlab = 'Degrees of Freedom', ylab='Density for the chi^2 distribution')
for (i in 3:15){
  ix = dchisq(x=x, df=i)
  lines(x,ix,col=i)}

Resulting in this

chi-square

With higher Degrees of Freedom, the density of chi-square distribution is getting smaller.

We could also plot distribution function, quantile function and random generation, besides density function, switching dchisq command to pchisq or qchisq or rchisq.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s