# introduction

`dbMC` is a package for making inference about low-rank matrix completion using de-biased estimator. It comes with two functions:

- It provides a de-biased estimator for low-rank matrix completion from Chen et al (2019). This is the function 'dbmc()'.

- The other function is to compute the confidence intervals for an entry of interest for low-rank matrix completion using the de-biased estimator.

    library(dbMC)
    # simulated data
    require(softImpute)
    #> Loading required package: softImpute
    #> Loading required package: Matrix
    #> Loaded softImpute 1.4-1
    n = 100
    p = 100
    J = 2  # the true low-rank
    np = n*p
    sig2 = 1
    missfrac = 0.5
    # xtrue is the underlying matrix that we do not know and want to recover it
    xtrue = matrix(rnorm(n*J),n,J)%*%matrix(rnorm(J*p),J,p)
    # generating missing entries locations
    imiss = sample(np,np*missfrac,replace=FALSE)
    # xna is the observed matrix with missing entries
    xna = xtrue + matrix(rnorm(np, sd = sig2),nr = n,nc = p)
    xna[imiss] = NA
    lamda = 2.5*sig2*sqrt(n*p)

    # note that we only have xna as our initial data
    # first, fit a softImpute method
    fit1 = softImpute(xna, type = 'als')
    # complete the matrix by a softImpute method
    ximp = complete(xna,fit1)
    mean((ximp - xtrue)^2);rankMatrix(ximp,.1)[1]
    #> [1] 0.5562762
    #> [1] 7
    # now, de-biased the softImpute method
    x.db = dbmc(x = xna,
                ximp = ximp,
                entries_miss = imiss,
                est_rank = 2)
    # smaller mse with de-biased estimator
    mean((x.db - xtrue)^2);rankMatrix(x.db,.1)[1]
    #> [1] 0.09725576
    #> [1] 2

    # confidence intervals
    CI_mc(i=1,j=2,alpha = 0.05,X.db = x.db,missfrac = 0.5,est_rank = 2,sigma2 = 1)
    #> $CI
    #> [1] 1.684703 2.704853
    #>
    #> $`(i,j)`
    #> [1] 1 2
    #>
    #> $v.ij
    #> [1] 0.06772855
    # true value
    xtrue[1,2]
    #> [1] 0.2230841