This function calculates the \(M_{\hat{}}\) statistic, which measures the average squared discrepancy between local and global factor models across all assets and time periods. It quantifies the difference between locally estimated factors/loadings and their global counterparts.
compute_M_hat(
local_factors,
global_factors,
local_loadings,
global_loadings,
iT,
ip,
m
)A numeric scalar \(M_{\hat{}}\) representing the average squared discrepancy between local and global factor models across all assets and time periods.
A list where each element is a numeric matrix representing the local factor scores for a specific time period. Each matrix should have \(T\) rows (time periods) and \(m\) columns (factors).
A numeric matrix of global factor scores with \(T\) rows (time periods) and \(m\) columns (factors).
A list where each element is a numeric matrix representing the local factor loadings for a specific time period. Each matrix should have \(N\) rows (assets) and \(m\) columns (factors).
A numeric matrix of global factor loadings with \(N\) rows (assets) and \(m\) columns (factors).
An integer specifying the number of time periods.
An integer specifying the number of assets.
An integer specifying the number of factors.
The function performs the following steps:
Initializes the \(M_{\hat{}}\) statistic to zero.
If the number of factors \(m\) is equal to one, it ensures that
global_loadings and global_factors are treated as matrices.
Iterates over each asset \(i = 1\) to \(N\) and each time period \(t = 1\) to \(T\).
For each asset and time period, computes:
common_H1: The dot product of the local loadings and local factors.
common_H0: The dot product of the global loadings and global factors.
The squared difference \((common\_H1 - common\_H0)^2\) and adds it to \(M_{\hat{}}\).
After all iterations, normalizes \(M_{\hat{}}\) by dividing by the product of \(N\) and \(T\).