I want to estimate nonparametric estimates for an independent variable by using lokern package at R.
I have the below data which have 2 variables:
x: independent variable
y: dependent variable
data_test<-structure(list(y = c(0.875261480116371, 0.13319865469368, 0.00127171595390059,
0.120784784396633, 0.396145484602405, 0.0145083415906443, 0.126972404606687,
0.158633863426125, 0.307832433458906, 3.42112531824949, 0.0340520045576305,
0.0577209021937775, 0.0296622168402153, 0.519694575795073, 0.598147976985479,
0.0130977584533862, 0.158721871619698, 0.0345042704092106, 0.828465740122911,
0.288698762072103, 0.00612936654816416, 0.660590833311049, 0.744003852280185,
0.0218624098840227, 0.0643524619734905, 0.106603465426499, 0.996560657600869,
0.122380988335843, 0.533105113544206, 0.0275922420213573, 0.107316738492487,
0.560308948944375, 0.143056108849691, 0.0161973817777236, 0.131817444834554,
1.0931449919045, 0.676905541419034, 0.0264930182311347, 0.0219841874288544,
0.488998767576592, 0.0347315975270806, 0.0411243463454958, 0.239393381406891,
0.518050404977722, 0.0446311348629937, 1.06966798067092, 0.181537821115414,
0.0313727396250001, 0.0216034647860423, 0.0276009215712176, 0.363985328271051,
0.360296428331267, 0.0668551459074575, 0.0096603143441187, 0.0105876830440506,
0.417186148227153, 0.553820116962763, 0.0411408340216935, 0.171913862343572,
0.0514348158606772, 0.389026902873765, 0.185058082651845, 0.0369879163899647,
1.08104328029981, 0.00746768318488792, 0.605457684587019, 0.0144968484938537,
0.00602213252556212, 0.0866902221106011, 2.86731502732902, 0.0410085953665955,
0.013626354236944, 0.000188405910625031, 0.0585839444657251,
0.238292013239626, 0.0792612023923057, 0.108649755268567, 0.00461453622722967,
0.171731805762336, 0.375266208662383, 0.15081802592681, 0.0993654895544528,
1.04912058404724, 0.00688994906597782, 0.00131255129276553, 0.0299156532828988,
1.65913122506183, 1.2779796600082, 0.0635807935616347, 0.0350137919082677,
2.88472754915262, 0.451804325441365, 0.170435290928851, 0.153848212504272,
0.190051111767901, 0.0250402432610551, 1.27823234596823, 0.325244428486599,
2.55249481518541, 0.652738453178641), x = c(0.157051206555181,
93.5554103254521, 36.4963908754934, -3.56611266493445, 34.7541054260692,
-62.9400893391807, 12.0450577377795, -35.6331874250237, -39.828866846312,
55.4826489507221, -184.96284270765, 18.45318524202, 24.0251747535325,
-17.2227224445543, 72.0898450404128, 77.3400269579394, 11.4445438761823,
-39.8399136067962, 18.5753251409526, -91.0200933927729, -53.7306953307048,
7.82902710952271, -81.2767391884694, 86.2556579176221, -14.7859426091212,
25.3677870484381, -32.6501861291018, 99.8278847617673, 34.9829942023039,
73.0140475212959, -16.6109126845448, -32.7592335826843, 74.8537874088129,
-37.8227588694546, 12.7268934849489, 36.3066722290206, -104.553574396311,
82.2742694540057, -16.276676021576, -14.8270655993876, -69.9284468279249,
-18.6364153009855, 20.2791386270462, -48.9278429329243, 71.9757184735048,
21.1260821883741, 103.424754322692, 42.6072553816148, 17.7123515166677,
14.698117153582, -16.6135250838639, -60.331196596044, 60.0246972779761,
-25.8563620618713, 9.82868981305174, -10.2896467597535, -64.5899487712409,
74.419091432425, -20.2832034012612, -41.4624965895172, 22.6792451066338,
62.3720212013179, 43.0183777764626, -19.2322428203173, -103.973231184753,
8.64157577348479, -77.8111614478938, 12.0402859159796, 7.7602400256449,
-29.4432033091852, 169.331480455615, 20.2505790945828, 11.6731976068873,
-1.37261032571168, -24.2041204066012, -48.8151629352629, 28.1533661206446,
32.9620623245219, 6.79303777939566, -41.4405364060766, 61.2589755596993,
-38.8352965646988, 31.5222920414193, 102.426587566278, -8.30057170680298,
3.62291497659761, -17.2961421371642, -128.80726784859, -113.047762472691,
25.2152322142063, -18.7119726133478, -169.84485712416, -67.2163912629475,
41.2838092875223, -39.2234894552068, -43.5948519630358, 15.8241092201283,
113.058937991131, 57.0302050221283, -159.765290823302)), class = "data.frame", row.names = c(NA,
-100L))
I using lokern package at R to obtain nonparametric estimates for y.
Then I have the below simple code:
library(lokern)
model_np<-lokerns(y~x, data=data_test)
After executing the below code for getting estimates of y:
> predict(model_lok,data_test$x)
$x
[1] 0.1570512 93.5554103 36.4963909 -3.5661127 34.7541054 -62.9400893 12.0450577 -35.6331874 -39.8288668 55.4826490 -184.9628427
[12] 18.4531852 24.0251748 -17.2227224 72.0898450 77.3400270 11.4445439 -39.8399136 18.5753251 -91.0200934 -53.7306953 7.8290271
[23] -81.2767392 86.2556579 -14.7859426 25.3677870 -32.6501861 99.8278848 34.9829942 73.0140475 -16.6109127 -32.7592336 74.8537874
[34] -37.8227589 12.7268935 36.3066722 -104.5535744 82.2742695 -16.2766760 -14.8270656 -69.9284468 -18.6364153 20.2791386 -48.9278429
[45] 71.9757185 21.1260822 103.4247543 42.6072554 17.7123515 14.6981172 -16.6135251 -60.3311966 60.0246973 -25.8563621 9.8286898
[56] -10.2896468 -64.5899488 74.4190914 -20.2832034 -41.4624966 22.6792451 62.3720212 43.0183778 -19.2322428 -103.9732312 8.6415758
[67] -77.8111614 12.0402859 7.7602400 -29.4432033 169.3314805 20.2505791 11.6731976 -1.3726103 -24.2041204 -48.8151629 28.1533661
[78] 32.9620623 6.7930378 -41.4405364 61.2589756 -38.8352966 31.5222920 102.4265876 -8.3005717 3.6229150 -17.2961421 -128.8072678
[89] -113.0477625 25.2152322 -18.7119726 -169.8448571 -67.2163913 41.2838093 -39.2234895 -43.5948520 15.8241092 113.0589380 57.0302050
[100] -159.7652908
$y
[1] 0.2626652 1.0362184 0.2094705 0.2748579 0.1950373 0.4859794 0.2287054 0.3314901 0.3854881 0.3650532 1.9136908 0.2067608 0.1952171
[14] 0.3094527 0.4440854 0.5514184 0.2309087 0.3856282 0.2063207 0.6261288 0.4965176 0.2426026 0.5106526 0.8121246 0.3204007 0.1926424
[27] 0.3209612 1.1667891 0.1968960 0.4591294 0.3043276 0.3207863 0.4943471 0.2997292 0.2263014 0.2079326 -0.4634532 0.6883727 0.3070574
[40] 0.3060559 0.5260798 0.3100390 0.2012345 0.4686115 0.4423612 0.1996103 1.2168268 0.2730666 0.2096062 0.2199320 0.3089271 0.5184803
[53] 0.3813810 0.3121229 0.2365161 0.2944705 0.5235469 0.4854362 0.3001235 0.4050712 0.1974770 0.3866054 0.2773536 0.3101219 0.3747611
[66] 0.2402602 0.5215129 0.2287226 0.2427921 0.3237291 0.9836179 0.2013009 0.2300669 0.2681752 0.3179349 0.4678521 0.1877380 0.1846270
[79] 0.2453106 0.4048227 0.3843546 0.3362410 0.1819359 1.2044661 0.2748352 0.2530661 0.3095009 -0.0574095 0.2669386 0.1929319 0.3100428
[92] 0.5893979 0.5251369 0.2587267 0.3776657 0.4273564 0.2163135 1.2892692 0.3712811 -0.4768752
For example, for the value of x 0.157051, the estimated y value is 0.2626652.
Then, instead of using x as vector, I try to get estimates just only one input(x).
> predict(model_lok,0.1570512)
$x
[1] 0.1570512
$y
[1] 0.2626652
> predict(model_lok,-62.9400893)
$x
[1] -62.94009
$y
[1] 0.5221146
For x=0.1570512 , I get the same estimate as the previous one : y=0.2626652
However, for the 6th x value of the first vector x=-62.9400893, I got the estimate y=0.4859794 at the first table.
But at the second one(prediction just with one input), I get 0.5221146 different from the first result.
How can this be? Am I doing something wrong? Or is this something with versions of loaded packages? Are you getting the same results? Or is this a bug of the package? Or do i interpret result wrongly?
I will be very glad for any help. Thanks a lot.