Librerias

setwd("P:/2025-1/ADD 1/2do Parcial/simulation Monte")
library(triangle)
## Warning: package 'triangle' was built under R version 4.4.3

Simulacion de Montecarlo

Number of simulations

n <- 10000

Set seed for reproducibility

set.seed(123)

Simulate costs for each activity using different distributions

activity1 <- rnorm(n, mean = 10000, sd = 2000)       # Normal distribution
activity2 <- rlnorm(n, meanlog = 9.491, sdlog = 0.5) # Log-normal distribution (mean ~15,000)
activity3 <- runif(n, min = 5000, max = 25000)       # Uniform distribution
activity4 <- rtriangle(n, a = 8000, b = 15000, c = 10000) # Triangular distribution
activity5 <- 2000 + rbeta(n, 2, 5) * 8000            # Beta distribution scaled to 2000-10000

Calculo de Montecarlo

Calculate total project cost

total_cost <- activity1 + activity2 + activity3 + activity4 + activity5

Analyze results

Calculo del intervalo de confianza al 90%

summary(total_cost)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   29227   48013   54274   55247   61112  126569
quantile(total_cost, probs = c(0.05, 0.95))  # 90% confidence interval
##       5%      95% 
## 40396.84 73293.88

Plot histogram

hist(total_cost, breaks = 50, main = "Project Cost Distribution",
     xlab = "Total Cost", col = "skyblue", border = "white")

Calculate probability of exceeding different budget thresholds

cat("Probability cost exceeds $70,000:", mean(total_cost > 70000), "\n")
## Probability cost exceeds $70,000: 0.0781
cat("Probability cost exceeds $80,000:", mean(total_cost > 80000), "\n")
## Probability cost exceeds $80,000: 0.0196