Self function

Other articles with its own series, put together here

####################### function own, run directly call ################## ### 
function # of calculating mse 
mse = function (ei, p) #ei is residual vector, p is the number of the regression parameters 
{ 
  n-= length (EI) 
  SSE = SUM (EI ** 2) 
  mse = SSE / ( NP) 
  return (MSE) 
} 

# hat calculated matrix, and extracting the diagonal elements 
H = function (X) #X regression vector matrix 
{ 
  H *% =% X-Solve (T (X-)%% X-*)% * T% (X-) 
  HII = diag (H) 
  return (HII) 
} 

# Kaiman 
RI function = (EI, X-) 
{ 
  P = ncol (X-) # regression coefficient number 
  mse = mse (ei, p) # residual square 
  hii = H (X) # returns the diagonal elements of the matrix hat 
  ans = ei / sqrt (mse * (1-hii)) # Kaiman 
  return (ANS) 
} 

# external Kaiman 
ti = function (ei, X) # input variable regression residuals matrix 
{
  p = ncol (X) # number of regression parameters 
  n = length (ei) # number of data 
  hii = H (X) # Hat main diagonal elements of the matrix 
  s2_i = ((np) * mse (ei, p) - ( ei ** 2) / (1- hii)) / (np-1) # calculates S (I) ^ 2 
  ANS = EI / sqrt (s2_i * (. 1-HII)) 
  return (ANS) 
} 

# statistic calculation PRESS 
press = function (ei, X) #X is the design matrix argument 
{ 
  HII = H (X-) 
  RES = SUM ((EI / (. 1-HII)) ** 2) 
  #View (RES) 
} 

# PRESS is calculated prediction 2 ^ R & lt 
R_pred = function (X-, Y) 
{ 
  HII = H (X-) 
  EI = RESID (LM (X-Y ~ [, 2] X-+ [,. 3])) 
  PRESS = SUM ((EI / (l- HII)) ** 2) 
  SST = SUM ((Y-Mean (Y)) ** 2) 
  ANS-PRESS. 1 = / SST 
  return (ANS) 
} 

# draw a normal probability plot  
plot_ZP = function (ti) # external input Kaiman
{ 
  n-length = (Ti) 
  Order = Rank (Ti) # ascending order, t (i) is the first order a 
  Pi = (order-1/2 ) / n # cumulative probability 
  plot (ti, Pi, xlab = " student residuals", ylab = "percent") # Videos normal probability plot 
  # regression line 
  FM LM = (Pi ~ Ti) 
  abline (FM) 
} 

# test for lack of fit 
# Library (rsm) # rsm bag loading test for lack of fit 
# lm.rsm <-rsm (FO ~ Y (X)) 
# call loss # loftest (lm.rsm) fit test function loftest 

# calculation Dii ' 
Di_i = function (i, I_, MSE, beta1, Beta2, new_data) #i of the i-th point, i_ i_ first point, data dataset 
{ 
  one beta1 = * ($ new_data Cases [I] Cases -new_data $ [I _]) / sqrt (MSE) 
  tWO Beta2 = * (Distance new_data $ [I] - $ Distance new_data [I _]) / sqrt (MSE) 
  ANS = One ** 2 ** 2 + TWO 
  return (ANS) 
}

  

Guess you like

Origin www.cnblogs.com/jiaxinwei/p/11723668.html