vendredi 30 octobre 2020

How to know if a sample belongs to a new probability distribution?

I am trying to see if a sample (DemMesReal) belongs to a new discrete probability distribution (DemMesDistr).

This is the code I have made, however I do not know how to continue to do it. I've already thought about bootstrap, but I only want to see if the sample belongs to the probability distribution. The probability distribution returns 12 values for each sample (the same length of the original sample).

# Define seed
set.seed(12345)
# Original Sample
DemMesReal <- c(0, 230,   0,   0,   0, 151,   0,   0, 150,   0, 150,   0)

MonthsYear <- length(DemMesReal)
# Initial parameters
unif1min <- min(DemMesReal[which(DemMesReal>0)])
unif1max <- max(DemMesReal[which(DemMesReal>0)])
pber1 <- sum(DemMesReal==0)/MonthsYear


# Distribucion de probabilidad demanda mensual estocastica
DemMesDistr <- function(n=1, unif1min = 0, unif1max = 300, 
                        pber1=0, MonthsYear=12) {

# DemandaMensual Estocastica Resultados:
DemMesProb <- matrix(NA, nrow=n, ncol=MonthsYear)

for (j in 1:n){
# MONTHLY DEMAND: Bernouilli and Discrete uniform1

for (i in 1:MonthsYear) {
  
  # Bernouilli (inflated 0 Most of the days the products are not ordered)
  ber <- rbern(n=1, prob=1-pber1) # Most of the days of the month (70%) the customer does not order the product
  
  # Uniform1
  # If bernouilli distribution gives 1 (that month, the product analysed is ordered):
  if (ber==1) {DemMonth <- rdunif(n=1, min=unif1min, max=unif1max)}  # min=0 or 1 is not a problem: we re working with approx. (if 1 and unif2max=0: NA generated)
  # If bernouilli distribution gives 0 (that day the product is not ordered)
  if (ber==0) {DemMonth <- 0}
  
  # Monthly demand in Month i
  DemMesProb[j,i] <- DemMonth
 
}
}
DemMesProb
}

set.seed(12345)
# Probabilistic function obtaining 1000 samples
DemProb <- DemMesDistr(n=1000, unif1min, unif1max, pber1)
DemMesDistrVect <- as.vector(DemProb)
hist(DemMesDistrVect, freq=FALSE, breaks=10, main="Demanda Estocástica")
hist(DemMesReal, freq=FALSE, breaks=10, main="Demanda Real")

# Same number of Zeros
sum(DemMesDistrVect==0)/sum(length(DemMesDistrVect))
sum(DemMesReal==0)/sum(length(DemMesReal)) 

I do not know what to do more than the code I've made, to know if the sample belongs to the probability distribution (I can simulate lots of samples with the distribution).

Aucun commentaire:

Enregistrer un commentaire