HLM stands for Hierarchical Linear Model. HLM software is designed to do statistical analyses using data with a hierarchical structure. The HLM/2 program analyzes data with two hierarchical levels, for example students nested within schools. The HLM/3 program analyzes data with three hierarchical levels, for example students nested within classrooms, nested within schools. The conceptual approach is one in which the parameters of level-1 are considered to be functions of level-2 variables (for example).

The HLM software includes five modules, each designed for a different type of analysis:

  • HLM2 -- Two-level linear and nonlinear models
  • HLM3 -- Three-level linear and nonlinear models
  • HMLM -- Multivariate normal models with missing data
  • HMLM2 -- Multivariate normal models with missing data and "persons" nested in higher-level units
  • HCM2 -- Two-level cross-classified random-effects -- "persons" cross-classfied by two higher-level units

In version 6 of HLM, the "linear" component of the title is, to some extent, a misnomer, since version 6 also handles several nonlinear models, including bernoulii models (logistic regression), binomial models, poisson models, multinomial models and ordinal models.

The current release of the HLM programs is 6.02. The previous release was 5.00. There are several new features for release 6.02.


Where to Find HLM 6

Where can I use HLM 6 on campus?

HLM Version 6 statistical software for UNIX is available on strauss. The Windows version is available in the Research & Data Management Services Lab (room 002D Smith Hall).


Instructions for HLM 6

How do I run HLM 6 on Strauss?

These instructions are for running HLM programs on the UNIX server, strauss. For extensive tutorials on the Windows system, see the HLM Web site. Each of the five modules is run in two steps:

  1. Create an .mdm file.
  2. Run the analysis.

This document gives a complete example of how to create the .mdm file and run an HLM2 model. The other programs (HLM3, HMLM, and HMLM/2) run in an analogous fashion.

The UNIX commands for each of the programs are:

  • HLM/2: hlm2
  • HLM/3: hlm3
  • HMLM: hmlm
  • HMLM/2: hmlm2
  • HCM/2: hcm2

(UNIX commands are in lower case.)


Data analysis using the HLM/2 program typically has three stages:

  1. Create the .mdm file—the sufficient statistics matrices.
  2. Perform the analyses based on the .mdm file and optionally produce a file of residuals (resfile.cmd).
  3. Evaluate the model fit by analyzing the residual file. This last step is performed outside of the HLM/2 program.

Command summary for HLM/2

This section contains general instructions for preparing the command files and running the program. Detailed examples are contained in command files and interactive sessions accessible from this document as links.

Step 1: How to create the .mdm file

To create the .mdm file interactively, at the strauss prompt type


and respond to the prompts.

To create the .mdm file using batch mode, create a UNIX file which contains the responses to the program's prompts. Then, if the file is named hsb.mdmt, at the strauss prompt, type:

hlm2 -R hsb.mdmt

The command file hsb.mdmt contains short keywords or phrases preceding a colon (:) or preceded by an asterisk (*) describing each entry. For example,


indicates that the type of input data is an ASCII text file. And the variable names for each level are demarcated by a beginning and ending keyphrase. The level-one variables in this example are set off by *begin l1vars and *end l1vars.

*begin l1vars MINORITY FEMALE SES MATHACH *end l1vars

Notice that the file name extension for the command file to create the .mdm file changed in version HLM 5 and later  from .rsp to .mdmt.

Whether you run interactively or use batch mode, the program creates a file named creatmdm.mdmt in your current working directory. The file is a log of all the information accepted by the program as responses to its prompts. This log file can be renamed and used as a subsequent input file to create an .mdm file. If you run batch mode, creatmdm.mdmt will be identical to your command file hsb.mdmt.

Phase one of the analysis, creating the .mdm file, writes descriptive statistics for all variables to the screen and to a file named HLM2MDM.STS in your current working directory. (Remember that UNIX file names are case-sensitive.) If the file already exists, its contents are replaced. If you want to save a record of these statistics for each of the multiple runs, make a copy of the HLM2MDM.STS file before executing a new run. For example,

cp HLM2MDM.STS hsbModel1.sts

How to translate the .mdm file into an ASCII file

This step is generally not needed. However, if you want to read the contents of the .mdm file in an editor or another program, you must first translate it into an ASCII file. For example, to translate a file named hsb.mdm into an ASCII file named hsb.suffstat, at the strauss prompt, type:

prssm2 hsb.mdm > ! hsb.suffstat

In this example, the text version of the .mdm file is stored in hsb.suffstat. To view it, use an editor like pico or a pager like less. For example,

less hsb.suffstat

The pager named less is a UNIX program that displays text on the terminal screen one page at a time. Use the following keys to navigate through the text:

q: quit spacebar: Down one screen b: Back one screen j or down-arrow: Down one line k or up-arrow: Up one line /<string>: Search forward for <string> (replace <string> with the text you want to find) ?<string>: Search backwards for <string> (replace <string> with the text you want to find)

Or you can bypass creation of an output file by piping the output directly into the pager program:

prssm2 hsb.mdm | less

(The vertical bar (|) is the pipe symbol.)

Step 2: How to execute the analysis phase

For the most part, you can use these commands as you did version 5 commands. You can run interactively or with the command-line arguments indicating the name of your command files.

To proceed interactively using a .mdm file named hsb.mdm as input. Type:

hlm2 hsb.mdm

The program will use the default settings for analysis commands. These defaults are stored in /opt/hlm6/comfile2.hlm.

To proceed in batch mode using a .mdm file named hsb.mdm and a command file named hsb2.hlm, type:

hlm2 hsb.mdm hsb2.hlm

Since a command file is specified here, the default file (/opt/hlm6/comfile2.hlm) is ignored. All information needed by the program can be placed in your command file. If you do not specify all the required information in your command file, the program may prompt you for the additional information.

Whether you run interactively or batch mode, the program produces two output files. One is called newcmd.hlm. This file echos the commands used for the analysis. The second file contains the statistical output. Its file name is the name you give to the prompt, Enter name of output file: or enter in the command file after the OUTPUT: keyword, in this example, OUTPUT:newcmd.out.

A history of all iterations is printed to your screen. Selected iteration output is written to your output file. If you need all the iterations, you may redirect the screen output to a file. Be sure the file name is different from the name of the output file you specified in the .hlm file. For example,

hlm2 hsb.mdm hsb2.hlm > ! hsb2.iterations

Many sample programs and sample data are available at ftp://ftp.lisrel.com/hlm/. (These are HLM programs. Both LISREL and HLM are distributed by Scientific Software, Inc.)


Step 3: How to evaluate the model fit

The residual files produced by hlm2 are used to evaluate the fit of the model. You check the fit with software other than HLM. If you request a residual file, HLM produces a command file for reading the residual data into SAS,© SPSS,© or other statistical software. (On UNIX, we recommend SAS.) You then run SAS to analyze the residuals.

For example, to produce a SAS command file just for level-one variables in the HSB example, include commands like the following in your hsb2.hlm file:


and do the HLM run batch mode. Here, the line RESFILTYPE:SAS indicates a SAS data set is requested. The line RESFIL1:Y requests a level-one residuals file, and RESFIL1NAME:resfil1.sas gives the name of the SAS command file. The line RESFIL2:N indicates no level-two residuals file is requested.

Next, to create a SAS system file, run SAS using the command file produced by HLM:

SAS resfil1.sas

The SAS command file produced by HLM contains no analyses; it just produces a permanent SAS dataset. You decide what analyses to do and use the SAS dataset (resfil2.sas7bdat) as input. For example, the SAS command file residAnalysis1.sas produces descriptive statistics for all variables (proc means), runs the univariate procedure to test for normality of residuals and produce a histogram, Q-Q plot and probability plot, and plots level-one residuals (l1resid) against the predicted values (fitval). For comparison, at the bottom after the title statement (title "Generated data: Normal error";), it also generates data with normally distributed residuals and carries out the same analysis as for the HSB data. Note: This example produces several high-resolution plots. Therefore, you must be connected to strauss with an X-terminal emulator like XMING or Cygwin for it to work.