A movie to illustrate how the sampling distribution of the product moment sample correlation coefficient \(r\) depends on the sample size \(n\) and on the true correlation \(\rho\).

corr_sim_movie(
  n = 30,
  rho = 0,
  panel_plot = TRUE,
  hscale = NA,
  vscale = hscale,
  delta_n = 1,
  delta_rho = 0.1,
  ...
)

Arguments

n

An integer scalar. The initial value of the sample size. Must not be less than 2.

rho

A numeric scalar. The initial value of the true correlation \(\rho\). Must be in [-1, 1].

panel_plot

A logical parameter that determines whether the plot is placed inside the panel (TRUE) or in the standard graphics window (FALSE). If the plot is to be placed inside the panel then the tkrplot library is required.

hscale, vscale

Numeric scalars. Scaling parameters for the size of the plot when panel_plot = TRUE. The default values are 1.4 on Unix platforms and 2 on Windows platforms.

delta_n

An integer scalar. The amount by which the value of the sample size is increased/decreased after one click of the +/- button.

delta_rho

A numeric scalar. The amount by which the value of rho is increased/decreased after one click of the +/- button.

...

Additional arguments to the rpanel functions rp.button and rp.doublebutton, not including panel, variable, title, step, action, initval, range.

Value

Nothing is returned, only the animation is produced.

Details

Random samples of size \(n\) are simulated from a bivariate normal distribution in which each of the variables has a mean of 0 and a variance of 1 and the correlation \(\rho\) between the variables is chosen by the user.

The movie contains two plots. On the top is a scatter plot of the simulated sample, illustrating the strength of the association between the simulated values of the variables. A new sample is produced by clicking "simulate another sample. For each simulated sample the sample (product moment) correlation coefficient \(r\) is calculated and displayed in the title of the top plot.

The values of the sample correlation coefficients are stored and are plotted in a histogram in the bottom plot. A rug displays the individual values, with the most recent value coloured red. As we accumulate a large number of values in this histogram the shape of the sampling distribution of \(r\) emerges. The exact p.d.f. of \(r\) is superimposed on this histogram, as is the value of \(\rho\).

The bottom plot can be changed in two ways: (i) a radio button can be pressed to replace the histogram and pdf with a plot of the empirical c.d.f. and exact cdf; (ii) the variable can be changed from \(\rho\) to Fisher's z-transformation \(F(\rho) = arctanh(\rho) = [ln(1+\rho) - ln(1-\rho)]/2\). For sufficiently large values of \(n\), \(F(\rho)\) has approximately a normal distribution with mean \(\rho\) and variance \(1 / (n - 3)\).

The values of the sample size \(n\) or true correlation coefficient \(\rho\) can be changed using the respective +/- buttons. If one of these is changed then the bottom plot is reset using the sample correlation coefficient of the first sample simulated using the new combination of \(n\) and \(\rho\).

See also

movies: a user-friendly menu panel.

smovie: general information about smovie.

Examples

corr_sim_movie(rho = 0.8)
corr_sim_movie(n = 10)