Mixed_Model_Spline_Fit: Fitting Mixed Models with Splines

Description Usage Arguments Details Value References See Also

Description

This function fits a mixed model with minimal user input.

Usage

1
2
Mixed_Model_Spline_Fit(Y, knots, K, P = 1, spline = "Radial", r = 1,
  theta = 2)

Arguments

Y

A tibble containing ID, Y, and x. Where ID is the distinction used between datasets, Y is the response variable and x is the predictor variable.

knots

OPTIONAL: A vector of knots to be used to compute random effects in mixed model. SUPPLY ONLY knots OR K, NOT BOTH.

K

OPTIONAL: A value for how many number knots the user would like: DO NOT SUPPLY BOTH knots AND K

P

OPTIONAL: A value for the degree of the polynomial. Default P = 1 for linear trend.

spline

OPTIONAL: A character indicating the type of spline basis function to use: "Radial" or "Truncated Poly".

r

OPTIONAL: A value for the degree of the radial basis function. Not used in the truncated polynomial basis function.

theta

OPTIONAL: A value for the range of the radial basis function. Not used in the truncated polynomial basis function.

Details

The trend function determined by P, is a polynomial: beta0 + beta1x + beta2x^2 + ... + betaPx^P. This forms the fixed effects part of the model. The bases at knots create the random effects part of the mixed model. The final model looks like:

y_i = beta0 + beta1x_i + beta2x_i^2 + ... + betaPx_i^P + sum_j=1^K (u_j B_j(x_i)) + epsilon_i.

Value

A large list is returned containing: Y, a tibble containing the inputted ID, y, x, and estimated fit of the data fitted. coeff_fixed a tibble containing ID, and the estimated fixed effects coefficients labeled beta0, beta1, ..., betaP. coeff_rand a tibble containing ID, and the estimated random effects coefficients labeled u1, u2, ..., uK.

References

\insertRef

wand2003unequalgroupoutlier

@examples library(tidyverse) x <- rep(c(1:1000), 100) Y <- rnorm(100*1000, x, 2500) ID <- rep(1:100, 1000) ID <- ID[order(ID)]

Y <- tibble(ID = ID, y = Y, x = x) knots <- choose_knots(Y, 40)

fit <- Mixed_Model_Spline_Fit(Y, knots, theta = 10)

ggplot(fit$Y, aes(x = x, y = fitted, group = ID))+ geom_line(alpha = .5)

See Also

Mixed_Spline_Fit_Single to fit a mixed model with splines on individual datasets.


cshannum/unequalgroupoutlier documentation built on May 13, 2019, 11:10 a.m.