-1
$\begingroup$

I'm trying to create two matrices one that can be filled with 0's and 0.25's and another with 0's and 1's.

vector <- c()
for(i in 1:1000){
  dummy_qt <- as.data.frame(matrix(sample(c(0, 0.25), 44, replace = TRUE), 4, 11))
  colnames(dummy_qt) <- c(2005:2015)
  boot_qt <- dummy_qt %>%
    summarise_all(funs(sum)) %>%
    sum()/11

  dummy_y <- as.data.frame(matrix(sample(c(0, 1), 44, replace = TRUE), 4, 11))
  colnames(dummy_y) <- c(2005:2015)
  boot_y <- dummy_y %>%
    mutate(sumrow = rowSums(.)/11) %>%
    select(sumrow) %>%
    sum()

  qt_y <- sum(boot_qt, boot_y)
  vector[i] <- qt_y
}

After creating the matrices, I run a mathematical formula, and put it into a vector. However, I know the maximum the matrix dummy_qt can get is 1 (as it is possible to see on the example below), and the dummy_y is 4 (as it is possible to see on the example below), making the final result 5 if all values within the matrix are 0.25 for the first matrix and 1 for the second.

For example:

dummy_qt <- as.data.frame(matrix(0.25, 4, 11))
dummy_y <- as.data.frame(matrix(1, 4, 11))
boot_qt <- dummy_qt %>%
    summarise_all(funs(sum)) %>%
    sum()/11
boot_y <- dummy_y %>%
    mutate(sumrow = rowSums(.)/11) %>%
    select(sumrow) %>%
    sum()
qt_y <- sum(boot_qt, boot_y)

Whenever I run this, usually the histogram shows that I only get values between 0 and 3.25 which doesn't reflect the reality. This is all based on a real world example where I often have those matrices without any 0's being that they are just filled with 0.25 or 1 values, depending on the matrix. Am I doing something wrong or does this make perfect sense statistically? My final goal is to get some CI, by bootstrapping.

$\endgroup$
  • $\begingroup$ Can the downvoter explain why he did so? I'm happy to add or remove info if it makes the post better. $\endgroup$ – FilipeTeixeira Mar 23 '18 at 17:33
2
$\begingroup$

Unless I am missing something about the matrix creation process, I believe the issue is just that you are looking for something that very (very) rarely occurs.  Here is my understanding (please correct if I am wrong):  the sample matrices are created by sampling from c(0,a) with equal probability to fill the matrix entries, and the maximum scores are obtained only if the matrix is all a’s.  However, this will only happen with probability $(\frac{1}{2})^{44}$, or 1 out of 17.6 trillion trials.  Thus, I’m not sure it should be surprising that the simulation results in values that don't quite reach the maximum value 4.

I hope this helps.

$\endgroup$
  • $\begingroup$ Indeed, it makes perfect sense. What I ask myself is how can someone get CIs for a "real world" originated matrix. In my case, that matrix can often be filled only with one value. Because so far my method just proves that the matrix isn't random, but there should be ways of getting CIs from it. $\endgroup$ – FilipeTeixeira Mar 26 '18 at 11:37
  • 1
    $\begingroup$ one strategy that might work is to simply shuffle an observed matrix and calculate the statistic on that shuffled version many times...that may give a bootstrapped CI. $\endgroup$ – Gregg H Mar 26 '18 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.