Title: | Project Risk Analysis |
---|---|
Description: | Data analysis for Project Risk Management via the Second Moment Method, Monte Carlo Simulation, Contingency Analysis, Sensitivity Analysis, Earned Value Management, Learning Curves, Design Structure Matrices, and more. |
Authors: | Paul Govan [aut, cre, cph] |
Maintainer: | Paul Govan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0 |
Built: | 2024-11-22 20:26:22 UTC |
Source: | https://github.com/paulgovan/pra |
Actual Cost (AC).
ac(actual_costs, time_period)
ac(actual_costs, time_period)
actual_costs |
Vector of actual costs incurred at each time period. |
time_period |
Current time period. |
The function returns the Actual Cost (AC) of work completed.
# Set the actual costs and current time period for a toy project. actual_costs <- c(9000, 18000, 36000, 70000, 100000) time_period <- 3 # Calculate the AC and print the results. ac <- ac(actual_costs, time_period) cat("Actual Cost (AC):", ac, "\n")
# Set the actual costs and current time period for a toy project. actual_costs <- c(9000, 18000, 36000, 70000, 100000) time_period <- 3 # Calculate the AC and print the results. ac <- ac(actual_costs, time_period) cat("Actual Cost (AC):", ac, "\n")
Contingency Calculation.
contingency(sims, phigh = 0.95, pbase = 0.5)
contingency(sims, phigh = 0.95, pbase = 0.5)
sims |
List of results from a Monte Carlo simulation. |
phigh |
Percentile level for contingency calculation. Default is 0.95. |
pbase |
Base level for contingency calculation. Default is 0.5 |
The function returns the value of calculated contingency.
# Set the number os simulations and the task distributions for a toy project. num_sims <- 10000 task_dists <- list( list(type = "normal", mean = 10, sd = 2), # Task A: Normal distribution list(type = "triangular", a = 5, b = 10, c = 15), # Task B: Triangular distribution list(type = "uniform", min = 8, max = 12) # Task C: Uniform distribution ) # Set the correlation matrix for the correlations between tasks. cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Run the Monte Carlo simulation. results <- mcs(num_sims, task_dists, cor_mat) # Calculate the contingency and print the results. contingency <- contingency(results, phigh = 0.95, pbase = 0.50) cat("Contingency based on 95th percentile and 50th percentile:", contingency)
# Set the number os simulations and the task distributions for a toy project. num_sims <- 10000 task_dists <- list( list(type = "normal", mean = 10, sd = 2), # Task A: Normal distribution list(type = "triangular", a = 5, b = 10, c = 15), # Task B: Triangular distribution list(type = "uniform", min = 8, max = 12) # Task C: Uniform distribution ) # Set the correlation matrix for the correlations between tasks. cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Run the Monte Carlo simulation. results <- mcs(num_sims, task_dists, cor_mat) # Calculate the contingency and print the results. contingency <- contingency(results, phigh = 0.95, pbase = 0.50) cat("Contingency based on 95th percentile and 50th percentile:", contingency)
Generate Correlation Matrix.
cor_matrix(num_samples = 100, num_vars = 5, dists = dists)
cor_matrix(num_samples = 100, num_vars = 5, dists = dists)
num_samples |
The number of samples to generate. |
num_vars |
The number of distributions to sample. |
dists |
A list describing each distribution. |
The function returns the correlation matrix for the distributions.
# List of probability distributions dists <- list( normal = function(n) rnorm(n, mean = 0, sd = 1), uniform = function(n) runif(n, min = 0, max = 1), exponential = function(n) rexp(n, rate = 1), poisson = function(n) rpois(n, lambda = 1), binomial = function(n) rbinom(n, size = 10, prob = 0.5) ) # Generate correlation matrix cor_matrix <- cor_matrix(num_samples = 100, num_vars = 5, dists = dists) # Print correlation matrix print(cor_matrix)
# List of probability distributions dists <- list( normal = function(n) rnorm(n, mean = 0, sd = 1), uniform = function(n) runif(n, min = 0, max = 1), exponential = function(n) rexp(n, rate = 1), poisson = function(n) rpois(n, lambda = 1), binomial = function(n) rbinom(n, size = 10, prob = 0.5) ) # Generate correlation matrix cor_matrix <- cor_matrix(num_samples = 100, num_vars = 5, dists = dists) # Print correlation matrix print(cor_matrix)
Cost Performance Index (CPI).
cpi(ev, ac)
cpi(ev, ac)
ev |
Earned Value. |
ac |
Actual Cost. |
The function returns the Cost Performance Index (CPI) of work completed.
# Set the BAC and actual % complete for an example project. bac <- 100000 actual_per_complete <- 0.35 # Calcualte the EV ev <- ev(bac, actual_per_complete) # Set the actual costs and current time period and calculate the AC. actual_costs <- c(9000, 18000, 36000, 70000, 100000) time_period <- 3 ac <- ac(actual_costs, time_period) # Calculate the CPI and print the results. cpi <- cpi(ev, ac) cat("Cost Performance Index (CPI):", cpi, "\n")
# Set the BAC and actual % complete for an example project. bac <- 100000 actual_per_complete <- 0.35 # Calcualte the EV ev <- ev(bac, actual_per_complete) # Set the actual costs and current time period and calculate the AC. actual_costs <- c(9000, 18000, 36000, 70000, 100000) time_period <- 3 ac <- ac(actual_costs, time_period) # Calculate the CPI and print the results. cpi <- cpi(ev, ac) cat("Cost Performance Index (CPI):", cpi, "\n")
Cost Variance (CV).
cv(ev, ac)
cv(ev, ac)
ev |
Earned Value. |
ac |
Actual Cost. |
The function returns the Cost Variance (CV) of work completed.
# Set the BAC and actual % complete for an example project. bac <- 100000 actual_per_complete <- 0.35 # Calcualte the EV ev <- ev(bac, actual_per_complete) # Set the actual costs and current time period and calculate the AC. actual_costs <- c(9000, 18000, 36000, 70000, 100000) time_period <- 3 ac <- ac(actual_costs, time_period) # Calculate the CV and print the results. cv <- cv(ev, ac) cat("Cost Variance (CV):", cv, "\n")
# Set the BAC and actual % complete for an example project. bac <- 100000 actual_per_complete <- 0.35 # Calcualte the EV ev <- ev(bac, actual_per_complete) # Set the actual costs and current time period and calculate the AC. actual_costs <- c(9000, 18000, 36000, 70000, 100000) time_period <- 3 ac <- ac(actual_costs, time_period) # Calculate the CV and print the results. cv <- cv(ev, ac) cat("Cost Variance (CV):", cv, "\n")
Estimate at Completion (EAC).
eac(bac, cpi)
eac(bac, cpi)
bac |
Budget at Completion (BAC) (total planned budget). |
cpi |
Cost Performance Index (CPI), the efficiency of cost utilization. |
The function returns the Estimate at Completion (EAC).
# Set the BAC and CPI for a toy project. bac <- 100000 cpi <- 0.83 # Calculate the EAC eac <- eac(bac, cpi) print(eac)
# Set the BAC and CPI for a toy project. bac <- 100000 cpi <- 0.83 # Calculate the EAC eac <- eac(bac, cpi) print(eac)
Earned Value (EV).
ev(bac, actual_per_complete)
ev(bac, actual_per_complete)
bac |
Budget at Completion (BAC) (total planned budget). |
actual_per_complete |
Actual work completion percentage. |
The function returns the Earned Value (EV) of work completed.
# Set the BAC and actual % complete for a toy project. bac <- 100000 actual_per_complete <- 0.35 # Calculate the EV and print the results. ev <- ev(bac, actual_per_complete) cat("Earned Value (EV):", ev, "\n")
# Set the BAC and actual % complete for a toy project. bac <- 100000 actual_per_complete <- 0.35 # Calculate the EV and print the results. ev <- ev(bac, actual_per_complete) cat("Earned Value (EV):", ev, "\n")
Fit a Sigmoidal Model.
fit_sigmoidal(data, x_col, y_col, model_type)
fit_sigmoidal(data, x_col, y_col, model_type)
data |
A data frame containing the time (x_col) and completion (y_col) vectors. |
x_col |
The name of the time vector. |
y_col |
The name of the completion vector. |
model_type |
The name of the sigmoidal model (Pearl, Gompertz, or Logistic). |
The function returns a list of results for the sigmoidal model.
# Set up a data frame of time and completion percentage data data <- data.frame(time = 1:10, completion = c(5, 15, 40, 60, 70, 75, 80, 85, 90, 95)) # Fit a logistic model to the data. fit <- fit_sigmoidal(data, "time", "completion", "logistic") # Use the model to predict future completion times. predictions <- predict_sigmoidal(fit, seq(min(data$time), max(data$time), length.out = 100), "logistic") # Plot the results. p <- ggplot2::ggplot(data, ggplot2::aes_string(x = "time", y = "completion")) + ggplot2::geom_point() + ggplot2::geom_line(data = predictions, ggplot2::aes(x = x, y = pred), color = "red") + ggplot2::labs(title = "Fitted Logistic Model", x = "time", y = "completion %") + ggplot2::theme_minimal() p
# Set up a data frame of time and completion percentage data data <- data.frame(time = 1:10, completion = c(5, 15, 40, 60, 70, 75, 80, 85, 90, 95)) # Fit a logistic model to the data. fit <- fit_sigmoidal(data, "time", "completion", "logistic") # Use the model to predict future completion times. predictions <- predict_sigmoidal(fit, seq(min(data$time), max(data$time), length.out = 100), "logistic") # Plot the results. p <- ggplot2::ggplot(data, ggplot2::aes_string(x = "time", y = "completion")) + ggplot2::geom_point() + ggplot2::geom_line(data = predictions, ggplot2::aes(x = x, y = pred), color = "red") + ggplot2::labs(title = "Fitted Logistic Model", x = "time", y = "completion %") + ggplot2::theme_minimal() p
Risk-based 'Grandparent' Design Structure Matrix (DSM).
grandparent_dsm(S, R)
grandparent_dsm(S, R)
S |
Resource-Task Matrix 'S' giving the links (arcs) between resources and tasks. |
R |
Risk-Resource Matrix 'R' giving the links (arcs) between risks and resources. |
The function returns the Risk-based 'Grandparent' DSM 'G' giving the number of risks shared between each task.
# Set the S and R matrices and print the results. S <- matrix(c(1, 1, 0, 0, 1, 0, 0, 1, 1), nrow = 3, ncol = 3) R <- matrix(c(1, 1, 1, 1, 0, 0), nrow = 2, ncol = 3) cat("Resource-Task Matrix:\n") print(S) cat("\nRisk-Resource Matrix:\n") print(R) # Calculate the Risk-based Grandparent Matrix and print the results. risk_dsm <- grandparent_dsm(S, R) cat("\nRisk-based 'Grandparent' DSM:\n") print(risk_dsm)
# Set the S and R matrices and print the results. S <- matrix(c(1, 1, 0, 0, 1, 0, 0, 1, 1), nrow = 3, ncol = 3) R <- matrix(c(1, 1, 1, 1, 0, 0), nrow = 2, ncol = 3) cat("Resource-Task Matrix:\n") print(S) cat("\nRisk-Resource Matrix:\n") print(R) # Calculate the Risk-based Grandparent Matrix and print the results. risk_dsm <- grandparent_dsm(S, R) cat("\nRisk-based 'Grandparent' DSM:\n") print(risk_dsm)
Monte Carlo Simulation.
mcs(num_sims, task_dists, cor_mat = NULL)
mcs(num_sims, task_dists, cor_mat = NULL)
num_sims |
The number of simulations. |
task_dists |
A list of lists describing each task distribution. |
cor_mat |
The correlation matrix for the tasks (Optional). |
The function returns a list of the total mean, variance, standard deviation, and percentiles for the project.
# Set the number of simulations and task distributions for a toy project. num_sims <- 10000 task_dists <- list( list(type = "normal", mean = 10, sd = 2), # Task A: Normal distribution list(type = "triangular", a = 5, b = 10, c = 15), # Task B: Triangular distribution list(type = "uniform", min = 8, max = 12) # Task C: Uniform distribution ) # Set the correlation matrix for the correlations between tasks. cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Run the Monte Carlo sumulation and print the results. results <- mcs(num_sims, task_dists, cor_mat) cat("Mean Total Duration:", results$total_mean, "\n") cat("Variance of Total Variance:", results$total_variance, "\n") cat("Standard Deviation of Total Duration:", results$total_sd, "\n") cat("5th Percentile:", results$percentiles[1], "\n") cat("Median (50th Percentile):", results$percentiles[2], "\n") cat("95th Percentile:", results$percentiles[3], "\n") hist(results$total_distribution, breaks = 50, main = "Distribution of Total Project Duration", xlab = "Total Duration", col = "skyblue", border = "white")
# Set the number of simulations and task distributions for a toy project. num_sims <- 10000 task_dists <- list( list(type = "normal", mean = 10, sd = 2), # Task A: Normal distribution list(type = "triangular", a = 5, b = 10, c = 15), # Task B: Triangular distribution list(type = "uniform", min = 8, max = 12) # Task C: Uniform distribution ) # Set the correlation matrix for the correlations between tasks. cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Run the Monte Carlo sumulation and print the results. results <- mcs(num_sims, task_dists, cor_mat) cat("Mean Total Duration:", results$total_mean, "\n") cat("Variance of Total Variance:", results$total_variance, "\n") cat("Standard Deviation of Total Duration:", results$total_sd, "\n") cat("5th Percentile:", results$percentiles[1], "\n") cat("Median (50th Percentile):", results$percentiles[2], "\n") cat("95th Percentile:", results$percentiles[3], "\n") hist(results$total_distribution, breaks = 50, main = "Distribution of Total Project Duration", xlab = "Total Duration", col = "skyblue", border = "white")
Resource-based 'Parent' Design Structure Matrix (DSM).
parent_dsm(S)
parent_dsm(S)
S |
Resource-Task Matrix 'S' giving the links (arcs) between resources and tasks. |
The function returns the Resource-based 'Parent' DSM 'P' giving the number of resources shared between each task.
# Set the S matrix for a toy project and print the results. s <- matrix(c(1, 1, 0, 0, 1, 0, 0, 1, 1), nrow = 3, ncol = 3) cat("Resource-Task Matrix:\n") print(s) # Calculate the Resource-based Parent DSM and print the results. resource_dsm <- parent_dsm(s) cat("\nResource-based 'Parent' DSM:\n") print(resource_dsm)
# Set the S matrix for a toy project and print the results. s <- matrix(c(1, 1, 0, 0, 1, 0, 0, 1, 1), nrow = 3, ncol = 3) cat("Resource-Task Matrix:\n") print(s) # Calculate the Resource-based Parent DSM and print the results. resource_dsm <- parent_dsm(s) cat("\nResource-based 'Parent' DSM:\n") print(resource_dsm)
Predict a Sigmoidal Function.
predict_sigmoidal(fit, x_range, model_type)
predict_sigmoidal(fit, x_range, model_type)
fit |
A list containing the results of a sigmoidal model. |
x_range |
A vector of time values for the prediction. |
model_type |
The type of model (Pearl, Gompertz, or Logistic) for the prediction. |
The function returns a table of results containing the time and predicted values.
# Set up a data frame of time and completion percentage data data <- data.frame(time = 1:10, completion = c(5, 15, 40, 60, 70, 75, 80, 85, 90, 95)) # Fit a logistic model to the data. fit <- fit_sigmoidal(data, "time", "completion", "logistic") # Use the model to predict future completion times. predictions <- predict_sigmoidal(fit, seq(min(data$time), max(data$time), length.out = 100), "logistic") # Plot the results. p <- ggplot2::ggplot(data, ggplot2::aes_string(x = "time", y = "completion")) + ggplot2::geom_point() + ggplot2::geom_line(data = predictions, ggplot2::aes(x = x, y = pred), color = "red") + ggplot2::labs(title = "Fitted Logistic Model", x = "time", y = "completion %") + ggplot2::theme_minimal() p
# Set up a data frame of time and completion percentage data data <- data.frame(time = 1:10, completion = c(5, 15, 40, 60, 70, 75, 80, 85, 90, 95)) # Fit a logistic model to the data. fit <- fit_sigmoidal(data, "time", "completion", "logistic") # Use the model to predict future completion times. predictions <- predict_sigmoidal(fit, seq(min(data$time), max(data$time), length.out = 100), "logistic") # Plot the results. p <- ggplot2::ggplot(data, ggplot2::aes_string(x = "time", y = "completion")) + ggplot2::geom_point() + ggplot2::geom_line(data = predictions, ggplot2::aes(x = x, y = pred), color = "red") + ggplot2::labs(title = "Fitted Logistic Model", x = "time", y = "completion %") + ggplot2::theme_minimal() p
Planned Value (PV).
pv(bac, schedule, time_period)
pv(bac, schedule, time_period)
bac |
Budget at Completion (BAC) (total planned budget). |
schedule |
Vector of planned work completion (in terms of percentage) at each time period. |
time_period |
Current time period. |
The function returns the Planned Value (PV) of work completed.
# Set the BAC, schedule, and current time period for a toy project. bac <- 100000 schedule <- c(0.1, 0.2, 0.4, 0.7, 1.0) time_period <- 3 # Calculate the PV and print the results. pv <- pv(bac, schedule, time_period) cat("Planned Value (PV):", pv, "\n")
# Set the BAC, schedule, and current time period for a toy project. bac <- 100000 schedule <- c(0.1, 0.2, 0.4, 0.7, 1.0) time_period <- 3 # Calculate the PV and print the results. pv <- pv(bac, schedule, time_period) cat("Planned Value (PV):", pv, "\n")
Sensitivity Analysis.
sensitivity(task_dists, cor_mat = NULL)
sensitivity(task_dists, cor_mat = NULL)
task_dists |
A list of lists describing each task distribution. |
cor_mat |
The correlation matrix for the tasks (Optional). |
The function returns a vector of sensitivity results with respect to each task.
# Set the task distributions for a toy project. task_dists <- list( list(type = "normal", mean = 10, sd = 2), # Task A: Normal distribution list(type = "triangular", a = 5, b = 15, c = 10), # Task B: Triangular distribution list(type = "uniform", min = 8, max = 12) # Task C: Uniform distribution ) # Set the correlation matrix between the tasks. cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Calculate the sensitivity of each task and print the results sensitivity_results <- sensitivity(task_dists, cor_mat) cat("Sensitivity of the variance in total cost with respect to the variance in each task cost:\n") print(sensitivity_results) # Build a vertical barchart and display the results. data <- data.frame( Tasks = c('A', 'B', 'C'), Sensitivity = sensitivity_results ) barplot(height=data$Sensitivity, names=data$Tasks, col='skyblue', horiz=TRUE, xlab = 'Sensitivity', ylab = 'Tasks')
# Set the task distributions for a toy project. task_dists <- list( list(type = "normal", mean = 10, sd = 2), # Task A: Normal distribution list(type = "triangular", a = 5, b = 15, c = 10), # Task B: Triangular distribution list(type = "uniform", min = 8, max = 12) # Task C: Uniform distribution ) # Set the correlation matrix between the tasks. cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Calculate the sensitivity of each task and print the results sensitivity_results <- sensitivity(task_dists, cor_mat) cat("Sensitivity of the variance in total cost with respect to the variance in each task cost:\n") print(sensitivity_results) # Build a vertical barchart and display the results. data <- data.frame( Tasks = c('A', 'B', 'C'), Sensitivity = sensitivity_results ) barplot(height=data$Sensitivity, names=data$Tasks, col='skyblue', horiz=TRUE, xlab = 'Sensitivity', ylab = 'Tasks')
Second Moment Analysis.
smm(mean, var, cor_mat = NULL)
smm(mean, var, cor_mat = NULL)
mean |
The mean vector. |
var |
The variance vector. |
cor_mat |
The correlation matrix (optional). |
The function returns a list of the total mean, variance, and standard deviation for the project.
# Set the mean vector, variance vector, and correlation matrix for a toy project. mean <- c(10, 15, 20) var <- c(4, 9, 16) cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Use the Second Moment Method to estimate the results for the project. result <- smm(mean, var, cor_mat) print(result)
# Set the mean vector, variance vector, and correlation matrix for a toy project. mean <- c(10, 15, 20) var <- c(4, 9, 16) cor_mat <- matrix(c( 1, 0.5, 0.3, 0.5, 1, 0.4, 0.3, 0.4, 1 ), nrow = 3, byrow = TRUE) # Use the Second Moment Method to estimate the results for the project. result <- smm(mean, var, cor_mat) print(result)
Schedule Performance Index (SPI).
spi(ev, pv)
spi(ev, pv)
ev |
Earned Value. |
pv |
Planned Value. |
The function returns the Schedule Performance Index (SPI) of work completed.
# Set the BAC, schedule, and current time period for an example project. bac <- 100000 schedule <- c(0.1, 0.2, 0.4, 0.7, 1.0) time_period <- 3 # Calculate the PV. pv <- pv(bac, schedule, time_period) # Set the actual % complete and calculate the EV. actual_per_complete <- 0.35 ev <- ev(bac, actual_per_complete) # Calculate the SPI and print the results. spi <- spi(ev, pv) cat("Schedule Performance Index (SPI):", spi, "\n")
# Set the BAC, schedule, and current time period for an example project. bac <- 100000 schedule <- c(0.1, 0.2, 0.4, 0.7, 1.0) time_period <- 3 # Calculate the PV. pv <- pv(bac, schedule, time_period) # Set the actual % complete and calculate the EV. actual_per_complete <- 0.35 ev <- ev(bac, actual_per_complete) # Calculate the SPI and print the results. spi <- spi(ev, pv) cat("Schedule Performance Index (SPI):", spi, "\n")
Schedule Variance (SV).
sv(ev, pv)
sv(ev, pv)
ev |
Earned Value. |
pv |
Planned Value. |
The function returns the Schedule Variance (SV) of work completed.
# Set the BAC, schedule, and current time period for an example project. bac <- 100000 schedule <- c(0.1, 0.2, 0.4, 0.7, 1.0) time_period <- 3 # Calculate the PV. pv <- pv(bac, schedule, time_period) # Set the actual % complete and calculate the EV. actual_per_complete <- 0.35 ev <- ev(bac, actual_per_complete) # Calculate the SV and print the results. sv <- sv(ev, pv) cat("Schedule Variance (SV):", sv, "\n")
# Set the BAC, schedule, and current time period for an example project. bac <- 100000 schedule <- c(0.1, 0.2, 0.4, 0.7, 1.0) time_period <- 3 # Calculate the PV. pv <- pv(bac, schedule, time_period) # Set the actual % complete and calculate the EV. actual_per_complete <- 0.35 ev <- ev(bac, actual_per_complete) # Calculate the SV and print the results. sv <- sv(ev, pv) cat("Schedule Variance (SV):", sv, "\n")