R version 4.4.0 alpha (2024-03-26 r86209 ucrt) Copyright (C) 2024 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("lpcde") > > set.seed(42) > n=1000 > x_data = matrix(rnorm(1*n, mean=0, sd=1), ncol=1) > y_data = matrix(rnorm(n, mean=0, sd=1)) > y_grid = stats::quantile(y_data, seq(from=0.1, to=0.9, by=0.1)) > > #bw estimation > model1 = lpbwcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw_type = "imse-rot") > summary(model1) Call: lpbwcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method imse-rot ================================== Index y_grid B.W. Eff.n ================================== 1 -1.2512 1.0910 305 2 -0.8452 1.0910 415 3 -0.5287 1.0910 477 4 -0.2550 1.0910 518 5 -0.0106 1.0910 528 ---------------------------------- 6 0.2397 1.0910 493 7 0.5039 1.0910 478 8 0.8026 1.0910 421 9 1.2896 1.0910 280 ================================== > > # density estimation > model2 = lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw=model1$BW[,2]) > summary(model2) Call: lpcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method ============================================================================= Point Std. Robust B.C. Index Grid B.W. Eff.n Est. Error [ 95% C.I. ] ============================================================================= 1 -1.2512 1.0910 304 0.1833 0.0049 0.1635 , 0.2081 2 -0.8452 1.0910 417 0.2823 0.0034 0.2788 , 0.3135 3 -0.5287 1.0910 481 0.3473 0.0029 0.3571 , 0.3866 4 -0.2550 1.0910 525 0.3731 0.0024 0.3804 , 0.4078 5 -0.0106 1.0910 532 0.3776 0.0022 0.3790 , 0.4046 ----------------------------------------------------------------------------- 6 0.2397 1.0910 503 0.3660 0.0023 0.3665 , 0.3931 7 0.5039 1.0910 480 0.3290 0.0023 0.3372 , 0.3637 8 0.8026 1.0910 426 0.2737 0.0025 0.2945 , 0.3259 9 1.2896 1.0910 281 0.1761 0.0049 0.1515 , 0.1943 ============================================================================= > > # non-negative and integrating to 1 density estimation > model2 = lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw=model1$BW[,2], nonneg=TRUE, normalize=TRUE) > summary(model2) Call: lpcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method ============================================================================= Point Std. Robust B.C. Index Grid B.W. Eff.n Est. Error [ 95% C.I. ] ============================================================================= 1 -1.2512 1.0910 304 0.2135 0.0049 0.1635 , 0.2081 2 -0.8452 1.0910 417 0.3288 0.0034 0.2788 , 0.3135 3 -0.5287 1.0910 481 0.4045 0.0029 0.3571 , 0.3866 4 -0.2550 1.0910 525 0.4345 0.0024 0.3804 , 0.4078 5 -0.0106 1.0910 532 0.4398 0.0022 0.3790 , 0.4046 ----------------------------------------------------------------------------- 6 0.2397 1.0910 503 0.4264 0.0023 0.3665 , 0.3931 7 0.5039 1.0910 480 0.3832 0.0023 0.3372 , 0.3637 8 0.8026 1.0910 426 0.3188 0.0025 0.2945 , 0.3259 9 1.2896 1.0910 281 0.2051 0.0049 0.1515 , 0.1943 ============================================================================= > > #bw estimation > model1 = lpbwcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw_type = "mse-rot") > summary(model1) Call: lpbwcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method mse-rot ================================== Index y_grid B.W. Eff.n ================================== 1 -1.2512 1.5034 527 2 -0.8452 1.6325 705 3 -0.5287 1.1896 531 4 -0.2550 1.0767 512 5 -0.0106 1.0492 503 ---------------------------------- 6 0.2397 1.0761 486 7 0.5039 1.1816 538 8 0.8026 1.5485 675 9 1.2896 1.4176 469 ================================== > > # density estimation > model2 = lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=0, bw=model1$BW[,2]) > summary(model2) Call: lpcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method ============================================================================= Point Std. Robust B.C. Index Grid B.W. Eff.n Est. Error [ 95% C.I. ] ============================================================================= 1 -1.2512 1.5034 529 0.1913 0.0025 0.1749 , 0.1945 2 -0.8452 1.6325 716 0.2737 0.0016 0.3039 , 0.3165 3 -0.5287 1.1896 538 0.3429 0.0024 0.3608 , 0.3848 4 -0.2550 1.0767 520 0.3737 0.0025 0.3799 , 0.4079 5 -0.0106 1.0492 507 0.3792 0.0024 0.3756 , 0.4037 ----------------------------------------------------------------------------- 6 0.2397 1.0761 493 0.3666 0.0023 0.3648 , 0.3924 7 0.5039 1.1816 537 0.3256 0.0018 0.3430 , 0.3642 8 0.8026 1.5485 678 0.2720 0.0011 0.2824 , 0.2928 9 1.2896 1.4176 467 0.1805 0.0020 0.1797 , 0.1980 ============================================================================= > > set.seed(42) > n=1000 > x_data = matrix(rnorm(2*n, mean=0, sd=1), ncol=2) > y_data = matrix(rnorm(n, mean=0, sd=1)) > y_grid = stats::quantile(y_data, seq(from=0.1, to=0.9, by=0.1)) > > #bw estimation > model1 = lpbwcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=matrix(c(0, 0), ncol=2), bw_type="imse-rot") > summary(model1) Call: lpbwcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method imse-rot ================================== Index y_grid B.W. Eff.n ================================== 1 -1.3242 0.8299 104 2 -0.8334 0.8299 157 3 -0.5201 0.8299 190 4 -0.2590 0.8299 210 5 0.0114 0.8299 216 ---------------------------------- 6 0.2612 0.8299 209 7 0.5211 0.8299 194 8 0.8037 0.8299 169 9 1.3115 0.8299 106 ================================== > > # density estimation > model2 = lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=matrix(c(0, 0), ncol=2), bw=model1$BW[,2]) Warning messages: 1: In sweep(x, 2, mx) : STATS is longer than the extent of 'dim(x)[MARGIN]' 2: In sqrt(abs(diag(covMat))) * sd_y * sd_x : longer object length is not a multiple of shorter object length 3: In sqrt(abs(diag(covMat_rbc))) * sd_y * sd_x : longer object length is not a multiple of shorter object length > summary(model2) Call: lpcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method ============================================================================= Point Std. Robust B.C. Index Grid B.W. Eff.n Est. Error [ 95% C.I. ] ============================================================================= 1 -1.3242 0.8299 102 0.1857 0.0258 0.0553 , 0.4167 2 -0.8334 0.8299 156 0.2866 0.0210 0.2045 , 0.5140 3 -0.5201 0.8299 186 0.3352 0.0165 0.2909 , 0.5410 4 -0.2590 0.8299 201 0.3682 0.0161 0.2635 , 0.5177 5 0.0114 0.8299 208 0.3777 0.0153 0.2384 , 0.4708 ----------------------------------------------------------------------------- 6 0.2612 0.8299 204 0.3574 0.0138 0.2944 , 0.5147 7 0.5211 0.8299 187 0.3204 0.0150 0.2083 , 0.4139 8 0.8037 0.8299 167 0.2618 0.0156 0.0791 , 0.3286 9 1.3115 0.8299 106 0.1781 0.0308 -0.0062 , 0.3041 ============================================================================= > > #bw estimation > model1 = lpbwcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=matrix(c(0, 0), ncol=2), bw_type="mse-rot") > summary(model1) Call: lpbwcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method mse-rot ================================== Index y_grid B.W. Eff.n ================================== 1 -1.3242 0.4586 22 2 -0.8334 0.4491 37 3 -0.5201 0.4901 46 4 -0.2590 0.5991 87 5 0.0114 1.5432 668 ---------------------------------- 6 0.2612 0.5930 80 7 0.5211 0.4884 48 8 0.8037 0.4503 30 9 1.3115 0.4578 21 ================================== > > # density estimation > model2 = lpcde(x_data=x_data, y_data=y_data, y_grid=y_grid, x=matrix(c(0, 0), ncol=2), bw=model1$BW[,2]) Warning messages: 1: In sweep(x, 2, mx) : STATS is longer than the extent of 'dim(x)[MARGIN]' 2: In sqrt(abs(diag(covMat))) * sd_y * sd_x : longer object length is not a multiple of shorter object length 3: In sqrt(abs(diag(covMat_rbc))) * sd_y * sd_x : longer object length is not a multiple of shorter object length > summary(model2) Call: lpcde Sample size 1000 Polynomial order for Y point estimation (p=) 2 Polynomial order for X point estimation (q=) 1 Density function estimated (mu=) 1 Order of derivative estimated for covariates (nu=) 0 Kernel function epanechnikov Bandwidth method ============================================================================= Point Std. Robust B.C. Index Grid B.W. Eff.n Est. Error [ 95% C.I. ] ============================================================================= 1 -1.3242 0.4586 23 0.2533 0.6140 -2.7680 , 3.2905 2 -0.8334 0.4491 37 0.4750 0.5940 -5.3537 , 4.9187 3 -0.5201 0.4901 44 0.7018 0.2912 -2.2817 , 6.1964 4 -0.2590 0.5991 86 0.4353 0.0978 -0.3112 , 1.2809 5 0.0114 1.5432 663 0.3496 0.0014 0.3865 , 0.4038 ----------------------------------------------------------------------------- 6 0.2612 0.5930 81 0.3687 0.0923 -0.3663 , 1.1810 7 0.5211 0.4884 48 0.2773 0.1032 -1.0740 , 1.4597 8 0.8037 0.4503 28 0.0813 0.2676 -1.6981 , 1.8804 9 1.3115 0.4578 19 0.0001 0.0017 -0.6869 , 0.7258 ============================================================================= > > proc.time() user system elapsed 246.95 6.50 253.57