# Loglinear analysis (/docs/analyses/loglinear)



## When to use it [#when-to-use-it]

Use loglinear analysis when you have two or more categorical variables and you want a model of the cell counts, not a single chi-square. A saturated model fits every cell. An independence model says the variables are unrelated.

## Assumptions [#assumptions]

Cells should not be mostly empty. Tensr stores `sparse_cell_fraction`. The saturated model has no residual degrees of freedom, so its likelihood-ratio chi-square is 0 and its comparison p is empty.

## Running it in Tensr [#running-it-in-tensr]

<Steps>
  <Step>
    Analyze → Loglinear → General. In chat: “Loglinear model of gender by region.”
  </Step>

  <Step>
    Select at least two categorical columns. Model starts at saturated.
  </Step>
</Steps>

## Options [#options]

<TypeTable
  type="{
  columns: {
    type: 'string[]',
    description: 'Categorical variables. At least two.',
  },
  model: {
    type: 'saturated | custom',
    description: 'Saturated fits every cell.',
    default: 'saturated',
  },
  max_iterations: {
    type: 'number',
    description: 'Iteration cap for the fit.',
    default: '20',
  },
  decimal_places: {
    type: '0–6',
    description: 'Report output. Decimal places.',
    default: '3',
  },
  apa_format: {
    type: 'boolean',
    description: 'Report output. APA-style p-values.',
    default: 'true',
  },
  include_charts: {
    type: 'boolean',
    description: 'Report output. Shared chart switch.',
    default: 'true',
  },
}"
/>

## Reading the output [#reading-the-output]

Teaching method and time of day. The independence model. Time was balanced inside each method, so the two factors were not built to be associated.

| Cell                | Observed | Expected |
| ------------------- | -------: | -------: |
| Lecture, Afternoon  |       16 |       16 |
| Lecture, Morning    |       16 |       16 |
| Online, Afternoon   |       16 |       16 |
| Online, Morning     |       16 |       16 |
| Workshop, Afternoon |       16 |       16 |
| Workshop, Morning   |       16 |       16 |

Every teaching method × time cell has the same count, and the independence model expects that same count. Goodness-of-fit p = > .999. Method and time of day are not associated. The coefficient rows for this balanced table are numerical zeros, so use the cell table and the fit p.

## Reporting (APA 7) [#reporting-apa-7]

An independence loglinear model fit the method × time table, p = > .999, N = 96. Teaching method and time of day were not associated.

## Coming from SPSS [#coming-from-spss]

Analyze → Loglinear → General. The route is on the Analyze menu.
