none
nls.lm from minpack.lm package returns not reproducible results RRS feed

  • Question

  • As I have asked here[1], I'm running a nonlinear lest squares using the minpack.lm package on Microsoft version or R. However, for each replication, with the same data, the output varies. In fact, my interest lies in the second parameter, however, even it suffers some variation.

    nlminb would return the same awkward output.

    If I use the CRAN version of R, the results are reproducible.

    library(minpack.lm) df_ss <- read.csv("example.csv") objective <- function(start, data_ss = df_ss) { beta_const <- start[1] beta_1 <- start[2:2] beta_poly <- start[-(1:2)] poly_df <- with(data_ss, cbind((var5 - var4 * beta_1))) poly_df <- poly(poly_df, degree = 2, raw = TRUE) poly_df <- poly_df %*% diag(beta_poly, nrow = length(beta_poly)) lp2 <- qr(cbind(const = 1 * beta_const, poly_df)) lp2 <- with(data_ss, qr.resid(lp2, y_ss - data_ss$var4 * beta_1)) return(lp2) } start <- rep(0, 4) ss_reg <- nls.lm(par = start, fn = objective) print(ss_reg$par) #2.227202e-06 -1.660069e-01 4.659955e-07 2.169863e-07 ss_reg <- nls.lm(par = start, fn = objective) print(ss_reg$par) #-1.022907e-06 -1.658407e-01 4.678488e-08 9.447334e-07 ss_reg <- nls.lm(par = start, fn = objective) print(ss_reg$par) #1.911939e-06 -1.658408e-01 2.513519e-07 -2.140628e-07 ss_reg <- nls.lm(par = start, fn = objective) print(ss_reg$par) #-5.765922e-07 -1.658408e-01 3.606956e-07 5.372434e-07

    Data is here[2].

    [1] stackoverflow.com/questions/43774514/in-microsoft-r-nls-lm-from-minpack-lm-package-returns-not-reproducible-results

    [2] drive.google.com/file/d/0Bz0Xdb-xV8O-RHJiN2cwMkJnREU/view?usp=sharing


    Friday, May 5, 2017 3:31 AM