Home > Software engineering >  estimating table values from values of sums of rows and columns
estimating table values from values of sums of rows and columns

Time:11-16

I'm trying to estimate values from within a table that would sum the known values to the sum of columns and rows.

In other words, suppose I didn't have the values of the cells in yellow from the table below, but only the sums of rows and columns in blue. How to estimate (the hidden) table values (VL'[r,c]) from values of sums of rows and columns?

data table

The constrains would be VL'[r,c] >=0 AND VL'[r,c] <= max(SP[r],FG[c])

I have tried some forms of optimization to minimize the difference between the given values (sums of columns and rows) and the sums of individual values obtained in an iterative processes, but to no avail.

One of the reference pages was: https://palomar.home.ece.ust.hk/MAFS6010R_lectures/Rsession_solvers.html

Are there any functions or packages in R that can be used to estimate the values of the table from the values of the sums of its rows and columns?

Here's a small script to generate example data.

dat <- data.frame(
    SP=rep(c('SP1','SP2','SP3','SP4','SP5'),5),
    FG=rep(c('FG1','FG2','FG3','FG4','FG5'),5,each=5),
    VL=round(runif(25,50,500))
    )

tab <- xtabs(VL~SP FG,dat)
SP <- apply(tab,1,sum)
FG <- apply(tab,2,sum)

r <- 3
c <- 2

tab[r,c]

# constrains
# tab[r,c] >=0 AND
# tab[r,c] <= max(SP[r],FG[c])

CodePudding user response:

If r and c are non-negative vectors of row and column totals whose sums are equal then using only base R r2dtable(n, r, c) will give n random tables with the prescribed margins.

If you have an optimization criterion calculate it for each such matrix and take the one having the best value as an estimate or if any feasible solution to the constraints is fine then just use n=1.

Also see matrix_estimation in the NetworkRiskMeasures CRAN package.

  • Related