R Under development (unstable) (2025-06-30 r88369 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(distfreereg) > > all.equal.distfreereg <- distfreereg:::all.equal.distfreereg > test_dfr_functions <- distfreereg:::test_dfr_functions > > n <- 1e2 > func <- function(X, theta) theta[1] + theta[2]*X[,1] + theta[3]*X[,2] > set.seed(20250516) > Sig <- rWishart(1, df = n, Sigma = diag(n))[,,1] > X <- matrix(rexp(2*n, rate = 1), nrow = n) > theta <- c(2,5,1) > Y <- distfreereg:::f2ftheta(f = func, X)(theta) + + as.vector(distfreereg:::rmvnorm(n = n, reps = 1, mean = rep(0,n), SqrtSigma = distfreereg:::matsqrt(Sig))) > > df_nls <- as.data.frame(cbind(Y, X, rep(1:10, 10))) > names(df_nls) <- c("z", "x", "y", "g") > wt <- rexp(n) + 1 > form_nls <- z ~ d + e*x + f*y > > set.seed(20250516) > dfr_form_nls <- distfreereg(test_mean = form_nls, data = df_nls, + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE)) Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > > dfr_form_nls Number of observations: 100 Length of EPSP: 100 Monte Carlo simulations: 10000 Estimated parameter values: d e f 5.509e+00 5.972e+00 -1.310e+00 Observed statistics: Stat Value Pr(>Value) MCSE KS 5.778e-01 7.964e-01 4.027e-03 CvM 7.806e-02 6.843e-01 4.648e-03 --- `MCSE' is the Monte Carlo standard error of the estimated p-value. > > > set.seed(20250516) > dfr_form_nls_no_weights <- distfreereg(test_mean = form_nls, data = df_nls, + method = "nls", + control = list(return_on_error = FALSE)) Extracting covariance structure from nls object... Calculating Jacobian from 'nls' object... Retrieving Jacobian from 'nls' object... Retrieving fitted values from 'nls' object... Calculating the inverse square root of the covariance matrix... Calculating mu... Ordering observations by simplex method... Calculating transformation anchors... Calculating r_tilde... Calculating residuals... All covariate observations are unique; no grouping done... Calculating empirical partial sum process... Calculating observed statistic(s)... Running Monte Carlo simulation... ...1000 of 10000 ...2000 of 10000 ...3000 of 10000 ...4000 of 10000 ...5000 of 10000 ...6000 of 10000 ...7000 of 10000 ...8000 of 10000 ...9000 of 10000 ...10000 of 10000 Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > > newdata_nls <- data.frame(a = rnorm(10), b = rnorm(10)) > test_dfr_functions(dfr_form_nls, newdata = newdata_nls) d e f 5.51 5.97 -1.31 Waiting for profiling to be done... 2.5% 97.5% d 1.08 9.930 e 3.16 8.790 f -3.59 0.967 [1] 9.63 11.60 9.54 22.60 13.50 8.15 9.10 5.20 10.60 8.93 7.13 4.70 [13] 5.17 7.71 8.75 9.17 7.81 4.27 12.40 8.98 16.90 10.40 4.88 5.63 [25] 5.76 11.00 13.60 5.25 6.50 8.63 24.30 26.00 3.52 16.70 15.90 7.32 [37] 9.51 6.90 9.04 16.90 7.18 5.37 5.44 4.80 7.41 8.75 8.60 8.71 [49] 4.16 17.80 7.99 19.00 6.95 17.80 26.30 5.48 5.77 7.35 3.36 9.34 [61] 12.80 11.60 4.61 4.25 9.33 19.20 6.76 15.10 15.20 13.90 7.61 8.69 [73] 24.10 12.90 6.42 15.40 5.74 6.02 17.60 7.65 6.40 8.57 3.54 6.46 [85] 5.90 14.20 7.03 6.76 15.50 15.80 5.83 12.60 16.20 5.98 7.06 9.76 [97] 12.20 12.80 18.70 8.74 [1] 9.63 11.60 9.54 22.60 13.50 8.15 9.10 5.20 10.60 8.93 7.13 4.70 [13] 5.17 7.71 8.75 9.17 7.81 4.27 12.40 8.98 16.90 10.40 4.88 5.63 [25] 5.76 11.00 13.60 5.25 6.50 8.63 24.30 26.00 3.52 16.70 15.90 7.32 [37] 9.51 6.90 9.04 16.90 7.18 5.37 5.44 4.80 7.41 8.75 8.60 8.71 [49] 4.16 17.80 7.99 19.00 6.95 17.80 26.30 5.48 5.77 7.35 3.36 9.34 [61] 12.80 11.60 4.61 4.25 9.33 19.20 6.76 15.10 15.20 13.90 7.61 8.69 [73] 24.10 12.90 6.42 15.40 5.74 6.02 17.60 7.65 6.40 8.57 3.54 6.46 [85] 5.90 14.20 7.03 6.76 15.50 15.80 5.83 12.60 16.20 5.98 7.06 9.76 [97] 12.20 12.80 18.70 8.74 [1] 9.63 11.60 9.54 22.60 13.50 8.15 9.10 5.20 10.60 8.93 7.13 4.70 [13] 5.17 7.71 8.75 9.17 7.81 4.27 12.40 8.98 16.90 10.40 4.88 5.63 [25] 5.76 11.00 13.60 5.25 6.50 8.63 24.30 26.00 3.52 16.70 15.90 7.32 [37] 9.51 6.90 9.04 16.90 7.18 5.37 5.44 4.80 7.41 8.75 8.60 8.71 [49] 4.16 17.80 7.99 19.00 6.95 17.80 26.30 5.48 5.77 7.35 3.36 9.34 [61] 12.80 11.60 4.61 4.25 9.33 19.20 6.76 15.10 15.20 13.90 7.61 8.69 [73] 24.10 12.90 6.42 15.40 5.74 6.02 17.60 7.65 6.40 8.57 3.54 6.46 [85] 5.90 14.20 7.03 6.76 15.50 15.80 5.83 12.60 16.20 5.98 7.06 9.76 [97] 12.20 12.80 18.70 8.74 d e f d 4.97 -2.0500 -1.3600 e -2.05 2.0100 -0.0182 f -1.36 -0.0182 1.3200 > > m_nls <- nls(form_nls, data = df_nls, weights = wt) Warning message: In nls(form_nls, data = df_nls, weights = wt) : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > m_nls_na_omit <- update(m_nls, na.action = na.omit) Warning message: In nls(formula = form_nls, data = df_nls, weights = wt, algorithm = "default", : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > > set.seed(20250516) > dfr_nls <- distfreereg(test_mean = m_nls, verbose = FALSE, + control = list(return_on_error = FALSE)) > > dfr_nls Number of observations: 100 Length of EPSP: 100 Monte Carlo simulations: 10000 Estimated parameter values: d e f 5.509e+00 5.972e+00 -1.310e+00 Observed statistics: Stat Value Pr(>Value) MCSE KS 5.778e-01 7.964e-01 4.027e-03 CvM 7.806e-02 6.843e-01 4.648e-03 --- `MCSE' is the Monte Carlo standard error of the estimated p-value. > > test_dfr_functions(dfr_nls, newdata = newdata_nls) d e f 5.51 5.97 -1.31 Waiting for profiling to be done... 2.5% 97.5% d 1.08 9.930 e 3.16 8.790 f -3.59 0.967 [1] 9.63 11.60 9.54 22.60 13.50 8.15 9.10 5.20 10.60 8.93 7.13 4.70 [13] 5.17 7.71 8.75 9.17 7.81 4.27 12.40 8.98 16.90 10.40 4.88 5.63 [25] 5.76 11.00 13.60 5.25 6.50 8.63 24.30 26.00 3.52 16.70 15.90 7.32 [37] 9.51 6.90 9.04 16.90 7.18 5.37 5.44 4.80 7.41 8.75 8.60 8.71 [49] 4.16 17.80 7.99 19.00 6.95 17.80 26.30 5.48 5.77 7.35 3.36 9.34 [61] 12.80 11.60 4.61 4.25 9.33 19.20 6.76 15.10 15.20 13.90 7.61 8.69 [73] 24.10 12.90 6.42 15.40 5.74 6.02 17.60 7.65 6.40 8.57 3.54 6.46 [85] 5.90 14.20 7.03 6.76 15.50 15.80 5.83 12.60 16.20 5.98 7.06 9.76 [97] 12.20 12.80 18.70 8.74 [1] 9.63 11.60 9.54 22.60 13.50 8.15 9.10 5.20 10.60 8.93 7.13 4.70 [13] 5.17 7.71 8.75 9.17 7.81 4.27 12.40 8.98 16.90 10.40 4.88 5.63 [25] 5.76 11.00 13.60 5.25 6.50 8.63 24.30 26.00 3.52 16.70 15.90 7.32 [37] 9.51 6.90 9.04 16.90 7.18 5.37 5.44 4.80 7.41 8.75 8.60 8.71 [49] 4.16 17.80 7.99 19.00 6.95 17.80 26.30 5.48 5.77 7.35 3.36 9.34 [61] 12.80 11.60 4.61 4.25 9.33 19.20 6.76 15.10 15.20 13.90 7.61 8.69 [73] 24.10 12.90 6.42 15.40 5.74 6.02 17.60 7.65 6.40 8.57 3.54 6.46 [85] 5.90 14.20 7.03 6.76 15.50 15.80 5.83 12.60 16.20 5.98 7.06 9.76 [97] 12.20 12.80 18.70 8.74 [1] 9.63 11.60 9.54 22.60 13.50 8.15 9.10 5.20 10.60 8.93 7.13 4.70 [13] 5.17 7.71 8.75 9.17 7.81 4.27 12.40 8.98 16.90 10.40 4.88 5.63 [25] 5.76 11.00 13.60 5.25 6.50 8.63 24.30 26.00 3.52 16.70 15.90 7.32 [37] 9.51 6.90 9.04 16.90 7.18 5.37 5.44 4.80 7.41 8.75 8.60 8.71 [49] 4.16 17.80 7.99 19.00 6.95 17.80 26.30 5.48 5.77 7.35 3.36 9.34 [61] 12.80 11.60 4.61 4.25 9.33 19.20 6.76 15.10 15.20 13.90 7.61 8.69 [73] 24.10 12.90 6.42 15.40 5.74 6.02 17.60 7.65 6.40 8.57 3.54 6.46 [85] 5.90 14.20 7.03 6.76 15.50 15.80 5.83 12.60 16.20 5.98 7.06 9.76 [97] 12.20 12.80 18.70 8.74 d e f d 4.97 -2.0500 -1.3600 e -2.05 2.0100 -0.0182 f -1.36 -0.0182 1.3200 > > stopifnot(all.equal(dfr_nls, dfr_form_nls)) > > set.seed(20250516) > dfr_nls_override <- distfreereg(test_mean = m_nls_na_omit, + override = list(J = dfr_nls[["J"]], + fitted_values = dfr_nls[["fitted_values"]]), + control = list(return_on_error = FALSE)) Extracting covariance structure from nls object... Using supplied Jacobian... Using supplied fitted values... Calculating the inverse square root of the covariance matrix... Calculating mu... Ordering observations by simplex method... Calculating transformation anchors... Calculating r_tilde... Calculating residuals... All covariate observations are unique; no grouping done... Calculating empirical partial sum process... Calculating observed statistic(s)... Running Monte Carlo simulation... ...1000 of 10000 ...2000 of 10000 ...3000 of 10000 ...4000 of 10000 ...5000 of 10000 ...6000 of 10000 ...7000 of 10000 ...8000 of 10000 ...9000 of 10000 ...10000 of 10000 > > > cdfr_form_nls <- asymptotics(dfr_form_nls, reps = 5) Calculating required true covariance specification matrices... Generating errors... Running simulation... Repetition 1 of 5 Repetition 2 of 5 Repetition 3 of 5 Repetition 4 of 5 Repetition 5 of 5 Warning messages: 1: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 2: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 3: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 4: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 5: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 6: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > cdfr_nls <- asymptotics(dfr_nls, reps = 5) Calculating required true covariance specification matrices... Generating errors... Running simulation... Repetition 1 of 5 Repetition 2 of 5 Repetition 3 of 5 Repetition 4 of 5 Repetition 5 of 5 Warning messages: 1: In nls(formula = form_nls, data = new_data, weights = wt, algorithm = "default", : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 2: In nls(formula = form_nls, data = new_data, weights = wt, algorithm = "default", : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 3: In nls(formula = form_nls, data = new_data, weights = wt, algorithm = "default", : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 4: In nls(formula = form_nls, data = new_data, weights = wt, algorithm = "default", : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 5: In nls(formula = form_nls, data = new_data, weights = wt, algorithm = "default", : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > > signif(rejection(cdfr_form_nls, alpha = c(0.1, 0.5))[,2:3], digits = 3) alpha rate 1 0.1 0.0 2 0.5 0.2 3 0.1 0.0 4 0.5 0.6 > signif(rejection(cdfr_nls, alpha = c(0.1, 0.5))[,2:3], digits = 3) alpha rate 1 0.1 0.0 2 0.5 0.4 3 0.1 0.0 4 0.5 0.4 > > > > > # Orderings > > set.seed(20250516) > dfr_nls_asis <- update(dfr_nls, ordering = "asis") > set.seed(20250516) > dfr_form_nls_asis <- update(dfr_form_nls, ordering = "asis") Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > stopifnot(all.equal(dfr_nls_asis, dfr_form_nls_asis)) > > set.seed(20250516) > dfr_nls_optimal <- update(dfr_nls, ordering = "optimal") > set.seed(20250516) > dfr_form_nls_optimal <- update(dfr_form_nls, ordering = "optimal") Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > stopifnot(all.equal(dfr_nls_optimal, dfr_form_nls_optimal)) > > set.seed(20250516) > dfr_nls_natural <- update(dfr_nls, ordering = "natural") > set.seed(20250516) > dfr_form_nls_natural <- update(dfr_form_nls, ordering = "natural") Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > stopifnot(all.equal(dfr_nls_natural, dfr_form_nls_natural)) > > set.seed(20250516) > form_nls_g <- z ~ d + e*x + f*y + I(0*is.numeric(g)) > m_nls_g <- nls(form_nls_g, data = df_nls, weights = wt) Warning message: In nls(form_nls_g, data = df_nls, weights = wt) : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > dfr_nls_g <- update(dfr_nls, ordering = list("g"), test_mean = m_nls_g) > set.seed(20250516) > dfr_form_nls_g <- update(dfr_form_nls, ordering = list("g"), test_mean = form_nls_g) Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > stopifnot(all.equal(dfr_nls_g, dfr_form_nls_g)) > > df_nls[dfr_nls_g[["res_order"]],][["g"]] [1] 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 [26] 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 [51] 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 [76] 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 > > set.seed(20250516) > dfr_nls_g_grouped <- update(dfr_nls_g, group = TRUE) > set.seed(20250516) > dfr_form_nls_g_grouped <- update(dfr_form_nls_g, group = TRUE) Warning message: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model > stopifnot(all.equal(dfr_nls_g_grouped, dfr_form_nls_g_grouped)) > > > > > > ### Partial output > > dfr_nls_partial <- distfreereg(test_mean = m_nls, verbose = FALSE, + control = list(orth_tol = 1e-100)) Warning message: Error encountered, partial results returned: Error in calc_mu(J = J_for_mu, solve_tol = solve_tol, orth_tol = orth_tol): crossprod(mu) is not equal to the identity matrix > names(dfr_nls_partial) [1] "call" "data" "test_mean" [4] "covariance" "theta_hat" "optimization_output" [7] "fitted_values" "J" "" > > > > ### Failures > > tryCatch(distfreereg:::distfreereg.formula(test_mean = "a", data = df_nls, + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE)), + error = function(e) warning(e) + ) Warning message: In distfreereg:::distfreereg.formula(test_mean = "a", data = df_nls, : is(test_mean, "formula") is not TRUE > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = df_nls, + theta_init = 1:3, + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE)), + error = function(e) warning(e) + ) Warning message: In validate_extra_arg_list(extra_arg_list, "distfreereg.formula()") : Unused arguments passed to distfreereg.formula() with name(s) theta_init > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = as.matrix(df_nls), + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE)), + error = function(e) warning(e) + ) Warning message: In validate_args_distfreereg_formula(test_mean = test_mean, data = data, : 'data' must be a data frame > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = data.frame(), + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE)), + error = function(e) warning(e) + ) Warning message: In validate_args_distfreereg_formula(test_mean = test_mean, data = data, : 'data' must have at least one row > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = df_nls, + method_args = "weights = wt", + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE)), + error = function(e) warning(e) + ) Warning message: In validate_args_distfreereg_formula(test_mean = test_mean, data = data, : method_args must be a list > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = df_nls, + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE), + override = list(theta_hat = 1:3)), + error = function(e) warning(e) + ) Warning message: In validate_args_distfreereg_formula(test_mean = test_mean, data = data, : distfreereg.formula() argument 'override' cannot have 'theta_hat' element > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = df_nls, + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE), + override = list(1:3)), + error = function(e) warning(e) + ) Warning messages: 1: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 2: In validate_named_list(override, valid_names = c("res_order", "r", : All elements of override must be named > > tryCatch(distfreereg:::distfreereg.formula(test_mean = form_nls, data = df_nls, + method_args = list(weights = wt), + method = "nls", verbose = FALSE, + control = list(return_on_error = FALSE), + override = list(a = 1:3)), + error = function(e) warning(e) + ) Warning messages: 1: In (function (formula, data = parent.frame(), start, control = nls.control(), : No starting values specified for some parameters. Initializing 'd', 'e', 'f' to '1.'. Consider specifying 'start' or using a selfStart model 2: In validate_named_list(override, valid_names = c("res_order", "r", : override has the following bad names: a > > tryCatch(distfreereg(test_mean = m_nls, control = "hello"), + error = function(e) warning(e) + ) Warning message: In validate_args_distfreereg_nls(test_mean = m, n = n, control = control, : 'control' must be NULL or a list > > proc.time() user system elapsed 13.60 0.51 14.10