model_fit: model_fit

Description Usage Arguments Details Value Examples

Description

function to fit a linear model

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
model_fit(
  mf,
  intercept,
  model = TRUE,
  x = FALSE,
  y = FALSE,
  qr = TRUE,
  offset,
  weights
)

Arguments

mf

a named dataframe of complete data

intercept

an interger equals to 0 or 1. If 0, intercept should not be included in the model

model

logical. If TRUE the the model frame is returned.

x

logical. If TRUE the the model matrix is returned.

y

logical. If TRUE the response is returned.

qr

logical. If TRUE the the QR is returned.

offset

'offset' is a vector with the same length of data. If null, the data frame "mf" does not contain an offset column, else, the offset column is offset vector

weights

'weights' is a vector with the same length of data. If null, the data frame "mf" does not contain an weights column, else, the weights column is offset vector

Details

you can use this function to fit for a linear model return a list of results.

Value

'model_fit' returns a list of results containing the following components:

fitted.values: a n*1 matrix containing the fitted value

beta_hat: a n*1 matrix containing the fitted coefficients

coefficients: a n*1 matrix containing the residuals (observed values - fitted values)

residuals: a n*1 matrix containing the residuals (observed values - fitted values)

offset: if not null, a n*1 matrix containing the offset values.

weights: if not null, a n*1 matrix containing the weights values.

Examples

1
2
3
x = as.data.frame(matrix(c(2,4,6,8,1.1,1.9,3.1,4.2,1,1,1,1,1,2,3,4),4,4))
names(x) <- c("O", "x", "(offsets)","(weights)")
m = model_fit(x,1,TRUE, TRUE, TRUE, TRUE, offset = c(1,1,1,1), weights = c(1:4))

lxfjwj/lmpackage documentation built on Dec. 21, 2021, 12:46 p.m.