Title: | Koul's Minimum Distance Estimation in Regression and Image Segmentation Problems |
---|---|
Description: | Many methods are developed to deal with two major statistical problems: image segmentation and nonparametric estimation in various regression models. Image segmentation is nowadays gaining a lot of attention from various scientific subfields. Especially, image segmentation has been popular in medical research such as magnetic resonance imaging (MRI) analysis. When a patient suffers from some brain diseases such as dementia and Parkinson's disease, those diseases can be easily diagnosed in brain MRI: the area affected by those diseases is brightly expressed in MRI, which is called a white lesion. For the purpose of medical research, locating and segment those white lesions in MRI is a critical issue; it can be done manually. However, manual segmentation is very expensive in that it is error-prone and demands a huge amount of time. Therefore, supervised machine learning has emerged as an alternative solution. Despite its powerful performance in a classification problem such as hand-written digits, supervised machine learning has not shown the same satisfactory result in MRI analysis. Setting aside all issues of the supervised machine learning, it exposed a critical problem when employed for MRI analysis: it requires time-consuming data labeling. Thus, there is a strong demand for an unsupervised approach, and this package - based on Hira L. Koul (1986) <DOI:10.1214/aos/1176350059> - proposes an efficient method for simple image segmentation - here, "simple" means that an image is black-and-white - which can easily be applied to MRI analysis. This package includes a function GetSegImage(): when a black-and-white image is given as an input, GetSegImage() separates an area of white pixels - which corresponds to a white lesion in MRI - from the given image. For the second problem, consider linear regression model and autoregressive model of order q where errors in the linear regression model and innovations in the autoregression model are independent and symmetrically distributed. Hira L. Koul (1986) <DOI:10.1214/aos/1176350059> proposed a nonparametric minimum distance estimation method by minimizing L2-type distance between certain weighted residual empirical processes. He also proposed a simpler version of the loss function by using symmetry of the integrating measure in the distance. Kim (2018) <DOI:10.1080/00949655.2017.1392527> proposed a fast computational method which enables practitioners to compute the minimum distance estimator of the vector of general multiple regression parameters for several integrating measures. This package contains three functions: KoulLrMde(), KoulArMde(), and Koul2StageMde(). The former two provide minimum distance estimators for linear regression model and autoregression model, respectively, where both are based on Koul's method. These two functions take much less time for the computation than those based on parametric minimum distance estimation methods. Koul2StageMde() provides estimators for regression and autoregressive coefficients of linear regression model with autoregressive errors through minimum distant method of two stages. The new version is written in Rcpp and dramatically reduces computational time. |
Authors: | Jiwoong Kim <jwboys26 at gmail.com> |
Maintainer: | Jiwoong Kim <[email protected]> |
License: | GPL-2 |
Version: | 3.2.1 |
Built: | 2024-11-20 06:32:44 UTC |
Source: | CRAN |
Check whether or not an input matrix includes any non-numeric values (NA, NULL, "", character, etc) before being used for training. If any non-numeric values exist, then TrainBuddle() or FetchBuddle() will return non-numeric results.
CheckNonNumeric(X)
CheckNonNumeric(X)
X |
an n-by-p matrix. |
A list of (n+1) values where n is the number of non-numeric values. The first element of the list is n, and all other elements are entries of X where non-numeric values occur. For example, when the (1,1)th and the (2,3)th entries of a 5-by-5 matrix X are non-numeric, then the list returned by CheckNonNumeric() will contain 2, (1,1), and (2,3).
n = 5; p = 5; X = matrix(0, n, p) #### Generate a 5-by-5 matrix which includes two NA's. X[1,1] = NA X[2,3] = NA lst = CheckNonNumeric(X) lst
n = 5; p = 5; X = matrix(0, n, p) #### Generate a 5-by-5 matrix which includes two NA's. X[1,1] = NA X[2,3] = NA lst = CheckNonNumeric(X) lst
Create various images such as circle, rectangle and random dots.
GenImg(nx, ny, Type = 1, bNoise = FALSE, sig_noise = 0.1)
GenImg(nx, ny, Type = 1, bNoise = FALSE, sig_noise = 0.1)
nx |
- Width of an image. |
ny |
- Length of an image. |
Type |
- Type of an image: 1, 2, and 3 for rectangle, circle, and random dots, respectively. |
bNoise |
- Option for including noise: TRUE or FALSE. |
sig_noise |
- Strength of noise: numeric value between 0 and 0.5. |
A list of information of a generated image.
ImgMat - a matrix whose entries are pixel values of a generated image.
S1 - an n1x2 matrix whose entries denote coordinates of white pixels of the image. n1 denotes the number of the white pixels.
S2 - an n2x2 matrix whose entries denote coordinates of black pixels of the image. n2 denotes the number of the black pixels.
######## Generate a 10x10 black-and-white rectangle image with some noise nx=10 ny=10 Type=1 bNoise=TRUE sig_noise=0.1 lst = GenImg(nx,ny,Type, bNoise, sig_noise) ImgMat = lst$ImgMat image(ImgMat, axes = FALSE, col = grey(seq(0, 1, length = 256)))
######## Generate a 10x10 black-and-white rectangle image with some noise nx=10 ny=10 Type=1 bNoise=TRUE sig_noise=0.1 lst = GenImg(nx,ny,Type, bNoise, sig_noise) ImgMat = lst$ImgMat image(ImgMat, axes = FALSE, col = grey(seq(0, 1, length = 256)))
Seperate an area of white pixels from a given image when there is some noise.
GetSegImage(ImgMat, p1, p2)
GetSegImage(ImgMat, p1, p2)
ImgMat |
- a matrix whose entries are pixel values of the image. |
p1 |
- a known value of white pixel (usually 1). |
p2 |
- a known value of black pixel (usually 0). |
A list of information of a segmented image.
SegImgMat - a matrix as a result of the image segmentation.
Estimated_S1 - an n1x2 matrix whose entries denote estimated coordinates of white pixels, corresponding to p1.
Estimated_S2 - an n2x2 matrix whose entries denote estimated coordinates of black pixels, corresponding to p2.
######## Generate a 10x10 black-and-white rectangle image with some noise nx=10 ny=10 Type=1 bNoise=TRUE sig_noise=0.1 lst = GenImg(nx,ny,Type, bNoise, sig_noise) ImgMat = lst$ImgMat image(ImgMat, axes = FALSE, col = grey(seq(0, 1, length = 256))) ######## Perform image segmentation p1=1 ### value of a white pixel p2=0 ### value of a black pixel lst = GetSegImage(ImgMat, p1, p2) EstImgMat = lst$SegImgMat image(EstImgMat, axes = FALSE, col = grey(seq(0, 1, length = 256)))
######## Generate a 10x10 black-and-white rectangle image with some noise nx=10 ny=10 Type=1 bNoise=TRUE sig_noise=0.1 lst = GenImg(nx,ny,Type, bNoise, sig_noise) ImgMat = lst$ImgMat image(ImgMat, axes = FALSE, col = grey(seq(0, 1, length = 256))) ######## Perform image segmentation p1=1 ### value of a white pixel p2=0 ### value of a black pixel lst = GetSegImage(ImgMat, p1, p2) EstImgMat = lst$SegImgMat image(EstImgMat, axes = FALSE, col = grey(seq(0, 1, length = 256)))
Estimates both regression and autoregressive coefficients in the model where
is autoregressive process of known order
q
Koul2StageMde( Y, X, D, b0, RegIntMeasure, AR_Order, ArIntMeasure, TuningConst = 1.345 )
Koul2StageMde( Y, X, D, b0, RegIntMeasure, AR_Order, ArIntMeasure, TuningConst = 1.345 )
Y |
- Vector of response variables in linear regression model. |
X |
- Design matrix of explanatory variables in linear regression model. |
D |
- Weight Matrix. Dimension of D should match that of X. Default value is XA where A=(X'X)^(-1/2). |
b0 |
- Initial value for beta. |
RegIntMeasure |
- Symmetric and |
AR_Order |
- Order of the autoregressive error. |
ArIntMeasure |
- Symmetric and |
TuningConst |
- Used only for Robust measure. |
MDE1stage - The list of the first stage minimum distance estimation result. It contains betahat1stage, residual1stage, and rho1stage.
betahat1stage - The first stage minimum distance estimators of regression coefficients.
residual1stage - Residuals after the first stage minimum distance estimation.
rho1stage - The first stage minimum distance estimators of autoregressive coefficients of the error.
MDE2stage - The list of the second stage minimum distance estimation result. It contains betahat2stage, residual2stage, and rho2stage.
betahat2stage - The second stage minimum distance estimators of regression coefficients.
residual2stage - Residuals after the second stage minimum distance estimation.
rho2stage - The second stage minimum distance estimators of autoregressive coefficients of the error.
[1] Kim, J. (2018). A fast algorithm for the coordinate-wise minimum distance estimation. J. Stat. Comput. Simul., 3: 482 - 497
[2] Kim, J. (2020). Minimum distance estimation in linear regression model with strong mixing errors. Commun. Stat. - Theory Methods., 49(6): 1475 - 1494
[3] Koul, H. L (1985). Minimum distance estimation in linear regression with unknown error distributions. Statist. Probab. Lett., 3: 1-8.
[4] Koul, H. L (1986). Minimum distance estimation and goodness-of-fit tests in first-order autoregression. Ann. Statist., 14 1194-1213.
[5] Koul, H. L (2002). Weighted empirical process in nonlinear dynamic models. Springer, Berlin, Vol. 166
KoulArMde() and KoulLrMde()
#################### n <- 10 p <- 3 X <- matrix(runif(n*p, 0,50), nrow=n, ncol=p) #### Generate n-by-p design matrix X beta <- c(-2, 0.3, 1.5) #### Generate true beta = (-2, 0.3, 1.5)' rho <- 0.4 #### True rho = 0.4 eps <- vector(length=n) xi <- rnorm(n, 0,1) #### Generate innovation from N(0,1) #### Generate autoregressive process of order 1 for(i in 1:n){ if(i==1){eps[i] <- xi[i]} else{eps[i] <- rho*eps[i-1] + xi[i]} } Y <- X%*%beta + eps ##################### D <- "default" #### Use the default weight matrix b0 <- solve(t(X)%*%X)%*%(t(X)%*%Y) #### Set initial value for beta IntMeasure <- "Lebesgue" ##### Define Lebesgue measure MDEResult <- Koul2StageMde(Y,X, "default", b0, IntMeasure, 1, IntMeasure, TuningConst = 1.345) MDE1stageResult <- MDEResult[[1]] MDE2stageResult <- MDEResult[[2]] beta1 <- MDE1stageResult$betahat1stage residual1 <- MDE1stageResult$residual1stage rho1 <- MDE1stageResult$rhohat1stage beta2 <- MDE2stageResult$betahat2stage residual2 <- MDE1stageResult$residual2stage rho2 <- MDE2stageResult$rhohat2stage
#################### n <- 10 p <- 3 X <- matrix(runif(n*p, 0,50), nrow=n, ncol=p) #### Generate n-by-p design matrix X beta <- c(-2, 0.3, 1.5) #### Generate true beta = (-2, 0.3, 1.5)' rho <- 0.4 #### True rho = 0.4 eps <- vector(length=n) xi <- rnorm(n, 0,1) #### Generate innovation from N(0,1) #### Generate autoregressive process of order 1 for(i in 1:n){ if(i==1){eps[i] <- xi[i]} else{eps[i] <- rho*eps[i-1] + xi[i]} } Y <- X%*%beta + eps ##################### D <- "default" #### Use the default weight matrix b0 <- solve(t(X)%*%X)%*%(t(X)%*%Y) #### Set initial value for beta IntMeasure <- "Lebesgue" ##### Define Lebesgue measure MDEResult <- Koul2StageMde(Y,X, "default", b0, IntMeasure, 1, IntMeasure, TuningConst = 1.345) MDE1stageResult <- MDEResult[[1]] MDE2stageResult <- MDEResult[[2]] beta1 <- MDE1stageResult$betahat1stage residual1 <- MDE1stageResult$residual1stage rho1 <- MDE1stageResult$rhohat1stage beta2 <- MDE2stageResult$betahat2stage residual2 <- MDE1stageResult$residual2stage rho2 <- MDE2stageResult$rhohat2stage
Estimates the autoressive coefficients in the where
is the vector of
observations at times
.
KoulArMde(X, AR_Order, IntMeasure, TuningConst = 1.345)
KoulArMde(X, AR_Order, IntMeasure, TuningConst = 1.345)
X |
- Vector of |
AR_Order |
- Order of the autoregression model. |
IntMeasure |
- Symmetric and |
TuningConst |
- Used only for Robust measure. |
rhohat - Minimum distance estimator of .
residual - Residuals after minimum distance estimation.
ObjVal - Value of the objective function at minimum distance estimator.
[1] Kim, J. (2018). A fast algorithm for the coordinate-wise minimum distance estimation. J. Stat. Comput. Simul., 3: 482 - 497
[2] Kim, J. (2020). Minimum distance estimation in linear regression model with strong mixing errors. Commun. Stat. - Theory Methods., 49(6): 1475 - 1494
[3] Koul, H. L (1985). Minimum distance estimation in linear regression with unknown error distributions. Statist. Probab. Lett., 3: 1-8.
[4] Koul, H. L (1986). Minimum distance estimation and goodness-of-fit tests in first-order autoregression. Ann. Statist., 14 1194-1213.
[5] Koul, H. L (2002). Weighted empirical process in nonlinear dynamic models. Springer, Berlin, Vol. 166
KoulLrMde() and Koul2StageMde()
##### Generate stationary AR(2) process with 10 observations n <- 10 q <- 2 rho <- c(-0.2, 0.8) ##### Generate true parameters rho = (-0.2, 0.8)' eps <- rnorm(n, 0,1) ##### Generate innovations from N(0,1) X <- rep(0, times=n) for (i in 1:n){ tempCol <- rep(0, times=q) for (j in 1:q){ if(i-j<=0){ tempCol[j] <- 0 }else{ tempCol[j] <- X[i-j] } } X[i] <- t(tempCol)%*% rho + eps[i] } IntMeasure <- "Lebesgue" ##### Define Lebesgue measure MDEResult <- KoulArMde(X, q, IntMeasure, TuningConst=1.345) rhohat <- MDEResult$rhohat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Degenerate" ##### Define degenerate measure at 0 MDEResult <- KoulArMde(X, q, IntMeasure, TuningConst=1.345) rhohat <- MDEResult$rhohat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Robust" ##### Define "Robust" measure at 0 TuningConst <- 3 ##### Define the tuning constant MDEResult <- KoulArMde(X, q, IntMeasure, TuningConst) resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function
##### Generate stationary AR(2) process with 10 observations n <- 10 q <- 2 rho <- c(-0.2, 0.8) ##### Generate true parameters rho = (-0.2, 0.8)' eps <- rnorm(n, 0,1) ##### Generate innovations from N(0,1) X <- rep(0, times=n) for (i in 1:n){ tempCol <- rep(0, times=q) for (j in 1:q){ if(i-j<=0){ tempCol[j] <- 0 }else{ tempCol[j] <- X[i-j] } } X[i] <- t(tempCol)%*% rho + eps[i] } IntMeasure <- "Lebesgue" ##### Define Lebesgue measure MDEResult <- KoulArMde(X, q, IntMeasure, TuningConst=1.345) rhohat <- MDEResult$rhohat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Degenerate" ##### Define degenerate measure at 0 MDEResult <- KoulArMde(X, q, IntMeasure, TuningConst=1.345) rhohat <- MDEResult$rhohat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Robust" ##### Define "Robust" measure at 0 TuningConst <- 3 ##### Define the tuning constant MDEResult <- KoulArMde(X, q, IntMeasure, TuningConst) resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function
Estimates the regression coefficients in the model .
KoulLrMde(Y, X, D, b0, IntMeasure, TuningConst = 1.345)
KoulLrMde(Y, X, D, b0, IntMeasure, TuningConst = 1.345)
Y |
- Vector of response variables in linear regression model. |
X |
- Design matrix of explanatory variables in linear regression model. |
D |
- Weight Matrix. Dimension of D should match that of X. Default value is XA where A=(X'X)^(-1/2). |
b0 |
- Initial value for beta. |
IntMeasure |
- Symmetric and |
TuningConst |
- Used only for Robust measure. |
betahat - Minimum distance estimator of .
residual - Residuals after minimum distance estimation.
ObjVal - Value of the objective function at minimum distance estimator.
[1] Kim, J. (2018). A fast algorithm for the coordinate-wise minimum distance estimation. J. Stat. Comput. Simul., 3: 482 - 497
[2] Kim, J. (2020). Minimum distance estimation in linear regression model with strong mixing errors. Commun. Stat. - Theory Methods., 49(6): 1475 - 1494
[3] Koul, H. L (1985). Minimum distance estimation in linear regression with unknown error distributions. Statist. Probab. Lett., 3: 1-8.
[4] Koul, H. L (1986). Minimum distance estimation and goodness-of-fit tests in first-order autoregression. Ann. Statist., 14 1194-1213.
[5] Koul, H. L (2002). Weighted empirical process in nonlinear dynamic models. Springer, Berlin, Vol. 166
KoulArMde() and Koul2StageMde()
#################### n <- 10 p <- 3 X <- matrix(runif(n*p, 0,50), nrow=n, ncol=p) #### Generate n-by-p design matrix X beta <- c(-2, 0.3, 1.5) #### Generate true beta = (-2, 0.3, 1.5)' eps <- rnorm(n, 0,1) #### Generate errors from N(0,1) Y <- X%*%beta + eps D <- "default" #### Use the default weight matrix b0 <- solve(t(X)%*%X)%*%(t(X)%*%Y) #### Set initial value for beta IntMeasure <- "Lebesgue" ##### Define Lebesgue measure MDEResult <- KoulLrMde(Y,X,D, b0, IntMeasure, TuningConst=1.345) betahat <- MDEResult$betahat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Degenerate" ##### Define degenerate measure at 0 MDEResult <- KoulLrMde(Y,X,D, b0, IntMeasure, TuningConst=1.345) betahat <- MDEResult$betahat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Robust" ##### Define "Robust" measure TuningConst <- 3 ##### Define the tuning constant MDEResult <- KoulLrMde(Y,X,D, b0, IntMeasure, TuningConst) betahat <- MDEResult$betahat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function
#################### n <- 10 p <- 3 X <- matrix(runif(n*p, 0,50), nrow=n, ncol=p) #### Generate n-by-p design matrix X beta <- c(-2, 0.3, 1.5) #### Generate true beta = (-2, 0.3, 1.5)' eps <- rnorm(n, 0,1) #### Generate errors from N(0,1) Y <- X%*%beta + eps D <- "default" #### Use the default weight matrix b0 <- solve(t(X)%*%X)%*%(t(X)%*%Y) #### Set initial value for beta IntMeasure <- "Lebesgue" ##### Define Lebesgue measure MDEResult <- KoulLrMde(Y,X,D, b0, IntMeasure, TuningConst=1.345) betahat <- MDEResult$betahat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Degenerate" ##### Define degenerate measure at 0 MDEResult <- KoulLrMde(Y,X,D, b0, IntMeasure, TuningConst=1.345) betahat <- MDEResult$betahat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function IntMeasure <- "Robust" ##### Define "Robust" measure TuningConst <- 3 ##### Define the tuning constant MDEResult <- KoulLrMde(Y,X,D, b0, IntMeasure, TuningConst) betahat <- MDEResult$betahat ##### Obtain minimum distance estimator resid <- MDEResult$residual ##### Obtain residual objVal <- MDEResult$ObjVal ##### Obtain the value of the objective function