Now copy this program into your Editor and run it.
# from 1 to 10 on each pass through
# i.e. likelihood is computed for correlations ranging from 0 to .9
|Figure 2: Output from Likelihood_demo|
For further demonstration, we'll take advantage of R's prepackaged datasets.
Why are we doing this?! Of course, if you want to know what the correlation is between two variables you can just compute it (and R will do that easily for you!). But what we've done here is rather different. We've considered how good a fit there is between the observed data and specific values of the correlation, ranging from 0 to .9. For the attitude data, the actual correlation is .82. The fit is poor (higher -LL values) if we test the data against values less than .6, reaching a peak -LL value (worst fit) if we assume the variables are uncorrelated, r = 0. The fit is not so bad, though for values from .7 to .9. This illustrates one feature of likelihood estimation - it can give an indication of how precise an estimate of a statistic is. But more importantly, this method comes into its own when we want to test a model that has several parameters and various constraints. Merely estimating a set of statistics from a dataset is not very exciting: but things get much more interesting when we start to develop models that aim to parsimoniously explain the data in terms of latent, unobserved variables. This will be clearer when we come (eventually!) to consider modeling twin data. But first, let's illustrate further using a more complicated dataset with 3 variables.
Our next script demonstrates how the same matrix formula for likelihood estimation works if we have three variables, and so three correlations to estimate: between variables 1 and 2, 1 and 3, and 2 and 3. We use this demonstration to show how some combinations of correlations yield incomputable likelihood estimates. Read this script and try to understand how it works; it can be useful to type it in to the console one step at a time and then look at the values of different variables, by typing their name into the Console.