FixedEffects.solve_coefficients!
— FunctionSolve a least square problem for a set of FixedEffects
solve_coefficients!(y, fes, w; method = :cpu, maxiter = 10000, double_precision = true, tol = 1e-8)
Returns $\beta = argmin_{b} \sum_i w_i(y_i - X_i'b)$ where X
denotes the matrix of fixed effects fes
.
Arguments
y
: AAbstractVector
fes
: AVector{<:FixedEffect}
w
: A vector of weights, i.e.AbstractWeights
method
: ASymbol
for the method. Default is :cpu. The option :gpu requiresusing CUDA
(in this case, it is recommanded to use the optiondouble_precision = false
).double_precision::Bool
: Should the demeaning operation use Float64 rather than Float32? Default to true.tol
: Tolerance. Default to 1e-8 ifdouble_precision = true
, 1e-6 otherwise.maxiter
: Maximum number of iterationsnthreads
: Number of threads
Returns
- $\beta$ : Solution of the least square problem
iterations
: Number of iterationsconverged
: Did the algorithm converge?
Fixed effects are generally not unique. We standardize the solution in the following way: the mean of fixed effects within connected components is zero (except for the first). This gives the unique solution in the case of two fixed effects.
Examples
using FixedEffects
p1 = repeat(1:5, inner = 2)
p2 = repeat(1:5, outer = 2)
x = rand(10)
solve_coefficients!(rand(10), [FixedEffect(p1), FixedEffect(p2)])
FixedEffects.solve_residuals!
— Functionsolve_residuals!(y, fes, w; method = :cpu, double_precision = true, tol = 1e-8, maxiter = 10000, )
Returns $y_i - X_i'\beta$ where $\beta = argmin_{b} \sum_i y_i - X_i'b$, where X
denotes the matrix of fixed effects fes
.
Arguments
y
: AAbstractVector
or AAbstractMatrix
fes
: AVector{<:FixedEffect}
w
: A vector of weights, i.e.AbstractWeights
method
: ASymbol
for the method. Default is :cpu. The option :gpu requiresusing CUDA
orusing Metal' (in this case, it is recommanded to use the option
double_precision = false`).double_precision::Bool
: Should the demeaning operation use Float64 rather than Float32? Default to true.tol
: Tolerance. Default to 1e-8 ifdouble_precision = true
, 1e-6 otherwise.maxiter
: Maximum number of iterations
Returns
res
: Residual of the least square problemiterations
: Number of iterationsconverged
: Did the algorithm converge?
Examples
using FixedEffects
p1 = repeat(1:5, inner = 2)
p2 = repeat(1:5, outer = 2)
solve_residuals!(rand(10), [FixedEffect(p1), FixedEffect(p2)])