Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views3 pages

RStudio

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

RStudio to model metabolic flux analysis based on the 3GP loop for glucose in the

range of [50, 200) and then plot the 3GP values and obtain the maximum:

# Load necessary packageslibrary(ROI)library(ROI.plugin.glpk)# Define


the range of glucoseglucose_range <- seq(50, 199, by = 1)# Define the
3GP loop functionthreeGP_loop <- function(glucose) { # Define the
stoichiometric matrix S <- matrix(c(-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 1, -1, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

RStudio to fit different functions to the input and output data and determine the best fit
function using the least squares method and the Root Mean Squared Error (RSME):

# Define the input and output data

X <- c(1.205171, 1.421403, 1.649859, 1.891825, 2.148721, 2.422119, 2.713753, 3.025541,


3.359603, 3.718282)

Y <- c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)

# Define the fit functions

linear_func <- function(x, a, b) {a * x + b}


exp_func <- function(x, a, b) {a * exp(b * x)}

log_func <- function(x, a, b) {a * log(x) + b}

combo_func <- function(x, a, b, c) {a * x + b * exp(c * x)}

# Perform the fit for each function using least squares

linear_fit <- lm(Y ~ X)

exp_fit <- nls(Y ~ exp_func(X, a, b), start = list(a = 1, b = 1))

log_fit <- nls(Y ~ log_func(X, a, b), start = list(a = 1, b = 1))

combo_fit <- nls(Y ~ combo_func(X, a, b, c), start = list(a = 1, b = 1, c = 1))

# Calculate the RSME for each fit function

linear_rsme <- sqrt(mean((Y - predict(linear_fit))^2))

exp_rsme <- sqrt(mean((Y - predict(exp_fit))^2))

log_rsme <- sqrt(mean((Y - predict(log_fit))^2))

combo_rsme <- sqrt(mean((Y - predict(combo_fit))^2))

# Print the RSME values for each fit function

print(paste("Linear RSME:", linear_rsme))

print(paste("Exponential RSME:", exp_rsme))

print(paste("Logarithmic RSME:", log_rsme))

print(paste("Combo RSME:", combo_rsme))

# Compare the RSME values for each fit function and select the best option

if (linear_rsme < exp_rsme & linear_rsme < log_rsme & linear_rsme < combo_rsme) {

print("The linear function is the best option.")

} else if (exp_rsme < log_rsme & exp_rsme < combo_rsme) {

print("The exponential function is the best option.")

} else if (log_rsme < combo_rsme) {

print("The logarithmic function is the best option.")

} else {

print("The combination of the linear and exponential functions is the best option.")
}

You might also like