[R] Orthogonal Nonlinear Least-Squares Regression in R

Lorenzo Isella lorenzo.isella at gmail.com
Sat Mar 19 21:28:48 CET 2016


Dear All,
I am trying my hands at orthogonal least square regression.
Have a look for instance at


http://bit.ly/1pB2aHX

https://cran.r-project.org/web/packages/onls/index.html

http://bit.ly/1XDkkTL

docs.scipy.org/doc/external/odrpack_guide.pdf

However, I am experiencing some problems with a simple example, just
to compare the results to a simple linear fit.

Have a look at the following snippet

################################################

library(onls)

dd <- structure(list(de_emp_mn_agg = c(9226, 9404, 9604, 10183, 10788,
11352, 11984, 12921, 14057, 15235, 15560, 15738, 16039, 16729,
17332, 18398, 19458, 20001, 19861, 20690, 21495, 21869, 22145,
22521), de_emp_ind_agg = c(43862, 40621, 37884, 36039, 35228,
34336, 33684, 33816, 33593, 33861, 33817, 33139, 32250, 31796,
31276, 30934, 31340, 32078, 31366, 30800, 31410, 31975, 32120,
32254), de_gov_exp_agg = c(1183695, 1281056, 1334560, 1390475,
1439175, 1472564, 1495661, 1520460, 1565451, 1604454, 1654996,
1672559, 1701664, 1722003, 1751547, 1793235, 1824640, 1874300,
1894248, 1939610, 2001224, 2056539, 2104642, 2156210), berd =
c(26245.5,
26579, 25933, 25910, 26816.6, 27211, 28909.8, 30334.44, 33622.55,
35600, 36331.9, 36950, 38029, 38363, 38651.038, 41148, 43034,
46073, 45275, 46929, 51077.2, 53790.1, 53566.2, 56226)), row.names =
c(NA,
24L), .Names = c("de_emp_mn_agg", "de_emp_ind_agg", "de_gov_exp_agg",
"berd"), class = "data.frame")


mm1 <- lm(berd~ de_emp_mn_agg+
                  de_emp_ind_agg+
		   de_gov_exp_agg ,
                  data=dd)
		  
#and now this fails

mm3 <- onls(berd~ K+ A*de_emp_mn_agg+
                  B*de_emp_ind_agg+
		    D*de_gov_exp_agg,
		    data=dd,
		    start = list(K=-5e4, A= 1,B =1, D=0.1 ))
						      



################################################


I get this error message

Error in mf[[varNamesRHS]] : recursive indexing failed at level 2

What am I doing wrong?

Here is my sessionInfo()

> sessionInfo()
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)

locale:
 [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C
  [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8
   [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8
    [7] LC_PAPER=en_GB.utf8       LC_NAME=C
     [9] LC_ADDRESS=C              LC_TELEPHONE=C
     [11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] onls_0.1-1       minpack.lm_1.2-0


Any suggestion is appreciated.
Many thanks

Lorenzo



More information about the R-help mailing list