Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中带向量变量的非线性回归_R_Function_Combinations_Non Linear Regression_Nls - Fatal编程技术网

R中带向量变量的非线性回归

R中带向量变量的非线性回归,r,function,combinations,non-linear-regression,nls,R,Function,Combinations,Non Linear Regression,Nls,我想找到参数a和b,使我的数据与nlsLM相匹配。我知道有三件事使得这比使用nlsLM的正常非线性回归更复杂: N_l是矢量化变量,函数应输出N_l所有可能值的最大值 变量m取决于N_l的值,它们之间的关系在dataframeMulti.Presence中给出 在术语combn(e,k,sum)中,e应该是应用非线性回归的数据帧DATA的e1、e2、eu 3、eu 4、eu 5列 我尝试使用以下方法: func <- function(N_b, N_l,A,x.sqr,e_1

我想找到参数
a
b
,使我的数据与
nlsLM
相匹配。我知道有三件事使得这比使用
nlsLM的正常非线性回归更复杂:

  • N_l
    是矢量化变量,函数应输出
    N_l
    所有可能值的最大值

  • 变量
    m
    取决于
    N_l
    的值,它们之间的关系在dataframe
    Multi.Presence
    中给出

  • 在术语
    combn(e,k,sum)
    中,
    e
    应该是应用非线性回归的数据帧
    DATA
    e1、e2、eu 3、eu 4、eu 5

  • 我尝试使用以下方法:

        func <- function(N_b, N_l,A,x.sqr,e_1,e_2,e_3,e_4,e_5,S,a,b) {
        R <- sapply(seq(N_l), function(k) {max(Multi.Presence$m[k] * ((k/N_b) + 
                    (A * combn(e,k,sum) / x.sqr) * (b*S^a)))})
          return(R)
        } 
    
        regression <- nlsLM(R ~ func(N_b, N_l,A,x.sqr,e_1,e_2,e_3,e_4,e_5,S,a,b), 
                 data = DATA, 
                 start = c(a = 0.01, b = 0.01))
    
        summary(regression)
    
         >dput(DATA)
         structure(list(N_b = c(5, 5, 5, 5, 5), N_l = c(4, 5, 4, 3, 4), 
         A = c(-12, -15, -12, -9, -12), x.sqr = c(1440, 2250, 
         1440, 810, 1440), e_1 = c(21.8, 29, 21.8, 14.6, 21.8), 
         e_2 = c(9.8, 17, 9.8, 2.6, 9.8), e_3 = c(-2.2, 5, -2.2, 
         -9.4, -2.2), e_4 = c(-14.2, -7, -14.2, 0, -14.2), 
         e_5 = c(0, 19, 0, 0, 0), S = c(12, 15, 12, 9, 12), 
         R = c(0.591896859, 0.65922266, 
         0.5562939413, 0.47407075, 0.597435113)), 
         row.names = c(NA, 5L), class = "data.frame")
    
         > dput(Multi.Presence)
         structure(list(N_l = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), m = c(1.2, 
         1, 0.85, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65)), row.names = c(NA, 
         -10L), class = "data.frame")
    
    R <- function(x){
      N_b <- x[1]
      N_l <- x[2]
      A <- x[3]
      x.sqr <- x[4]
      S <- x[10]
      e <- x[grepl("e_\\d",names(x))]
      f <- sapply(seq(N_l),function(k) max(Multi.Presence$m[k] * ((k/N_b) + 
                                           (A * combn(e,k,sum) / x.sqr) * S )))
      c(val = max(f), pos = which.max(f))
    }
    
    DATA.Proposed <- cbind(DATA, vars = t(apply(DATA, 1, R)))