R Under development (unstable) (2024-11-13 r87330 ucrt) -- "Unsuffered Consequences"
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])
> 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.0256     0.0568 ,  0.4152    
2      -0.8334    0.8299     156    0.2866    0.0212     0.2032 ,  0.5153    
3      -0.5201    0.8299     186    0.3352    0.0164     0.2920 ,  0.5400    
4      -0.2590    0.8299     201    0.3682    0.0162     0.2625 ,  0.5187    
5       0.0114    0.8299     208    0.3777    0.0152     0.2393 ,  0.4699    
-----------------------------------------------------------------------------
6       0.2612    0.8299     204    0.3574    0.0139     0.2935 ,  0.5156    
7       0.5211    0.8299     187    0.3204    0.0149     0.2091 ,  0.4130    
8       0.8037    0.8299     167    0.2618    0.0157     0.0780 ,  0.3297    
9       1.3115    0.8299     106    0.1781    0.0305    -0.0049 ,  0.3028    
=============================================================================
> 
> #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])
> 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.6090    -2.7431 ,  3.2656    
2      -0.8334    0.4491      37    0.4750    0.5990    -5.3966 ,  4.9616    
3      -0.5201    0.4901      44    0.7018    0.2888    -2.2469 ,  6.1616    
4      -0.2590    0.5991      86    0.4353    0.0986    -0.3179 ,  1.2875    
5       0.0114    1.5432     663    0.3496    0.0014     0.3866 ,  0.4038    
-----------------------------------------------------------------------------
6       0.2612    0.5930      81    0.3687    0.0931    -0.3728 ,  1.1874    
7       0.5211    0.4884      48    0.2773    0.1024    -1.0636 ,  1.4493    
8       0.8037    0.4503      28    0.0813    0.2698    -1.7130 ,  1.8954    
9       1.3115    0.4578      19    0.0001    0.0017    -0.6811 ,  0.7200    
=============================================================================
> 
> proc.time()
   user  system elapsed 
 242.56    6.21  249.01