---
title: "Introduction to ModLR"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to ModLR}
  %\VignetteEngine{knitr::rmarkdown}
---

```{r setup, include=FALSE}
library(ModLR)
```

# Overview
ModLR provides an information-theoretic framework for moderation analysis
using multi-model inference based on Akaike's Information Criterion (AIC and AICc).
Traditional approaches to moderation analysis typically rely on a single model
with an interaction term. However, such approaches may lead to spurious
moderation effects when nonlinear relationships are present but not properly modeled.
The ModLR package addresses this limitation by comparing multiple candidate
models and identifying the most appropriate specification based on information
criteria.

# Basic Example

```{r, eval=FALSE}

set.seed(123)

n <- 400

z <- sample(c(0, 1), n, replace = TRUE)
x <- ifelse(z == 0, runif(n, 0.5, 6.5), runif(n, 3.5, 9.5))
y <- (0.8 * x^2) + (30 * z) + rnorm(n, 0, 5)

ddat <- data.frame(x = x, y = y, z = z)

result <- moderated_regression(dat, iv = "x", moderator = "z", dv = "y")
print(result)
compare_models(result)
```

The output shows competing models ranked according to AIC or AICc. Lower values
indicate better model fit, allowing the researcher to identify whether the
interaction model is truly supported by the data.

# Interpreting Model Comparison

The ModLR framework evaluates alternative model specifications rather than relying
on a single model. This approach helps determine:

- whether the interaction model improves fit
- whether nonlinear models provide a better explanation
- the relative strength of evidence for each model

By focusing on model comparison, researchers can avoid incorrectly concluding that
moderation is present when it is actually due to model misspecification.

# Additional Analyses

## Simple Slopes

Simple slopes estimate the effect of the independent variable at specific levels
of the moderator, helping clarify how the relationship changes across conditions.


```{r, eval=FALSE}
simple_slopes(result)
```


## Johnson–Neyman Analysis

The Johnson–Neyman procedure identifies the range of moderator values for which
the effect of the independent variable is statistically significant.


```{r, eval=FALSE}
johnson_neyman(result)
```

## Visualization

Visualization helps communicate moderation effects clearly by showing how the
relationship between variables changes across levels of the moderator.


```{r, eval=FALSE}
plot_moderation(result)
```

# Methodological Background

The framework implemented in ModLR is based on Daryanto (2019), which proposes
an information-theoretic approach to moderation analysis. By comparing alternative
models using AIC/AICc, this approach reduces the risk of identifying spurious
moderation effects arising from nonlinear relationships.

# Conclusion

ModLR provides a principled approach to moderation analysis by integrating
multi-model inference with interpretation tools. The package allows researchers
to go beyond traditional single-model approaches and to conduct more robust and
reliable analyses.

# References

Daryanto, A. (2019). Avoiding spurious moderation effects: An information-theoretic
approach to moderation analysis. Journal of Business Research, 103, 110–118.
