How to create a command to choose linearization alternatives

3

I have the following command to get coefficients for linearisation of the Michaelis Menten function.

# "Estimativas para "CHUTE" 

# 1 para (Eadie-Hofstee  y = -B(y/x) + A)(Especialmente para RMSEA com valores nulos)
# 2 para (x = A(x/y) - B)
# 3 para (Hanes-Woolf  x/y = x/A + B/A)
# 4 para (Lineweaver-Burk  1/y = (B/Ax) + 1/A)

if(ch==1){

  #Alternativa 1   (Eadie-Hofstee  y = -B(y/x) + A)

  dados_Chute <- data.frame(Y=c(Indice),x=c(Indice)/(rep(c(pp), each=100)))   
  options(na.action=na.exclude)
  ajuste<-lm(Y~x,data=dados_Chute)
  A <- (ajuste[["coefficients"]][["(Intercept)"]])
  B <- -(ajuste[["coefficients"]][["x"]])
  C <- A
} else if(ch==2) {

  # Alternativa 2   (x = A(x/y) - B)

  dados_Chute <- data.frame(Y=(rep(c(pp), each=100)),x=(rep(c(pp), each=100))/(c(Indice)))  
  options(na.action=na.exclude)
  ajuste<-lm(Y~x,data=dados_Chute)
  A <- ajuste[["coefficients"]][["x"]]
  B <- -(ajuste[["coefficients"]][["(Intercept)"]])
  C <- 1 - A
} else if(ch==3){

  # Alternativa 3   (Hanes-Woolf  x/y = x/A + B/A)

  dados_Chute <- data.frame(Y = (rep(c(pp), each=100))/c(Indice),x = (rep(c(pp), each=100)))  
  options(na.action=na.exclude)
  ajuste<-lm(Y~x,data=dados_Chute)
  A <- 1/(ajuste[["coefficients"]][["x"]])
  B <- (ajuste[["coefficients"]][["(Intercept)"]])*A
  C <- 1 - A
} else if(ch==4){

  # Alternativa 4   (Lineweaver-Burk  1/y = (B/Ax) + 1/A)

  dados_Chute <- data.frame(Y = 1/c(Indice),x = 1/(rep(c(pp), each=100)))  
  options(na.action=na.exclude)
  ajuste<-lm(Y~x,data=dados_Chute)
  A <- 1/(ajuste[["coefficients"]][["(Intercept)"]])
  B <- (ajuste[["coefficients"]][["x"]])*A
  C <- 1 - A
} else {
  print ("Erro!")
}

I need to create a command in which the user of the program can choose between one of the alternatives to estimate the coefficients (from linearization), from the choice of 'ch', without having to repeat the whole command whenever one of the alternatives. I repeat this four times during my program (one for each calculated index (RMSEA, GFI, NFI and CFI). I am adjusting a curve the calculated estimates for several observation values and sometimes I have to choose one of the alternatives for linearization (not always is the same for all indexes).

    
asked by anonymous 28.09.2018 / 21:06

1 answer

3

One option would be to create a function with the option ch :

estimativa <- function(ch)
{
    # testes
    if(!ch %in% c(1:4)) stop("'ch' deve conter um valor entre 1 e 4")

    # "Estimativas para "CHUTE" 

    # 1 para (Eadie-Hofstee  y = -B(y/x) + A)(Especialmente para RMSEA com valores nulos)
    # 2 para (x = A(x/y) - B)
    # 3 para (Hanes-Woolf  x/y = x/A + B/A)
    # 4 para (Lineweaver-Burk  1/y = (B/Ax) + 1/A)

    if(ch==1){

      #Alternativa 1   (Eadie-Hofstee  y = -B(y/x) + A)

      dados_Chute <- data.frame(Y=c(Indice),x=c(Indice)/(rep(c(pp), each=100)))   
      options(na.action=na.exclude)
      ajuste<-lm(Y~x,data=dados_Chute)
      A <- (ajuste[["coefficients"]][["(Intercept)"]])
      B <- -(ajuste[["coefficients"]][["x"]])
      C <- A
    } else if(ch==2) {

      # Alternativa 2   (x = A(x/y) - B)

      dados_Chute <- data.frame(Y=(rep(c(pp), each=100)),x=(rep(c(pp), each=100))/(c(Indice)))  
      options(na.action=na.exclude)
      ajuste<-lm(Y~x,data=dados_Chute)
      A <- ajuste[["coefficients"]][["x"]]
      B <- -(ajuste[["coefficients"]][["(Intercept)"]])
      C <- 1 - A
    } else if(ch==3){

      # Alternativa 3   (Hanes-Woolf  x/y = x/A + B/A)

      dados_Chute <- data.frame(Y = (rep(c(pp), each=100))/c(Indice),x = (rep(c(pp), each=100)))  
      options(na.action=na.exclude)
      ajuste<-lm(Y~x,data=dados_Chute)
      A <- 1/(ajuste[["coefficients"]][["x"]])
      B <- (ajuste[["coefficients"]][["(Intercept)"]])*A
      C <- 1 - A
    } else if(ch==4){

      # Alternativa 4   (Lineweaver-Burk  1/y = (B/Ax) + 1/A)

      dados_Chute <- data.frame(Y = 1/c(Indice),x = 1/(rep(c(pp), each=100)))  
      options(na.action=na.exclude)
      ajuste<-lm(Y~x,data=dados_Chute)
      A <- 1/(ajuste[["coefficients"]][["(Intercept)"]])
      B <- (ajuste[["coefficients"]][["x"]])*A
      C <- 1 - A
    }

    return(c(A, B, C))
}
    
28.09.2018 / 21:52