Learn R Programming

saeMSPE (version 1.4)

varfh: Estimates of the variance component using several methods for Fay Herriot model

Description

This function returns the estimate of variance component with several existing method for Fay Herriot model. This function does not accept missing values

Usage

varfh(formula, data, D, method, na_rm, na_omit)
varOBP(formula, data, D, na_rm, na_omit)

Value

This function returns a list with components:

bhat

(vector) Estimates of the unknown regression coefficients.

Ahat

(numeric) Estimates of the variance component.

Arguments

formula

(formula). Stands for the model formula that specifies the auxiliary variables to be used in the regression model. This should follow the R model formula syntax.

data

(data frame). It represents the data containing the response values and auxiliary variables for the Nested Error Regression Model.

D

(vector). It represents the knowing sampling variance for Fay Herriot model.

method

Variance component estimation method. See "Details".

na_rm

A logical value indicating whether to remove missing values (NaN) from the input matrices and vectors. If TRUE, missing values in the input data (X, Y, and D) are automatically cleaned using internal functions. If FALSE, missing values are not removed. Defaults to FALSE.

na_omit

A logical value indicating whether to stop the execution if missing values (NaN) are present in the input data. If TRUE, the function will check for missing values in X, Y, and D. If any missing values are found, an error message will be raised, prompting the user to handle the missing data before proceeding. Defaults to FALSE.

Author

Peiwen Xiao, Xiaohui Liu, Yu Zhang, Yuzi Liu, Jiming Jiang

Details

Default value for method is 1, It represents the moment estimator, Also called ANOVA estimator, The available variance component estimation method are list as follows:

method = 1 represents the moment (MOM) estimator, ;

method = 2 represents the restricted maximum likelihood (REML) estimator;

method = 3 represents the maximum likelihood (ML) estimator;

method = 4 represents the empirical bayesian (EB) estimator;

References

J. Jiang. Linear and Generalized Linear Mixed Models and Their Applications. 2007.

Examples

Run this code
X <- matrix(runif(10 * 3), 10, 3)
X[,1] <- rep(1, 10) 
D <- (1:10) / 10 + 0.5
Y <- X %*% c(0.5, 1, 1.5) + rnorm(10, 0, sqrt(2)) + rnorm(10, 0, sqrt(D))

data <- data.frame(Y = Y, X1 = X[,2], X2 = X[,3])
formula <- Y ~ X1 + X2
result <- varfh(formula, data, D, method = 1)

Run the code above in your browser using DataLab