El mar, 19-05-2009 a las 17:17 +0200, Ikerne del Valle escribió: > > Dear all: > > I'm trying to fit the optimal Box-Cox > transformation related to nls (see the code > below) for the demand of money data in Green (3th > Edition) but in the last step R gives the next > error message. > Error en > `[.data.frame`(eval(object$data), , > as.character(formula(object)[[2]])[2]) : > undefined columns selected. > ¿Any idea to solve the problem? > Thanks in advance, > > > library(nlrwr) > r<-c(4.50,4.19,5.16,5.87,5.95,4.88,4.50,6.44,7.83,6.25,5.50,5.46,7.46,10.28,11.77,13.42,11.02,8.50,8.80,7.69) > M<-c(480.00,524.30,566.30,589.50,628.20,712.80,805.20,861.00,908.40,1023.10,1163.60,1286.60,1388.90,1497.90,1631.40,1794.40,1954.90,2188.80,2371.70,2563.60) > Y<-c(2208.30,2271.40,2365.60,2423.30,2416.20,2484.80,2608.50,2744.10,2729.30,2695.00,2826.70,2958.60,3115.20,3192.40,3187.10,3248.80,3166.00,3277.70,3492.00,3573.50) > money<-data.frame(r,M,Y) > attach(money) > ols1<-lm(log(M)~log(r)+log(Y)) > output1<-summary(ols1) > coef1<-ols1$coefficients > a1<-coef1[[1]] > b11<-coef1[[2]] > b21<-coef1[[3]] > money.m1<-nls(log(M)~a+b*r^g+c*Y^g,data=money,start=list(a=a1,b=b11,g=1,c=b21)) > summary(money.m1) > money.m2<-boxcox(money.m1) > > > > Prof. Ikerne del Valle Erkiaga > Department of Applied Economics V > Faculty of Economic and Business Sciences > University of the Basque Country > Avda. Lehendakari Agirre, Nº 83 > 48015 Bilbao (Bizkaia) Spain >
Ikerne, Inside boxcox.nls, the variable "log(M)" is searched in dataframe money and not found. Indeed, it is a little redundant to take logs and then search a Box-Cox transformation --which gives the log when lambda is zero. If you really want to do that, you might define a new variable "logM" and include that in your money dataframe, then rewrite the nls() call as: money.m1 <- nls(logM ~ a + b ... etc. Best, ft. -- Fernando TUSELL e-mail: Departamento de Econometría y Estadística fernando.tus...@ehu.es Facultad de CC.EE. y Empresariales Tel: (+34)94.601.3733 Universidad del País Vasco Secr: (+34)94.601.3740 Avenida Lendakari Aguirre, 83 Fax: (+34)94.601.3754 E-48015 BILBAO (Spain) http://www.et.bs.ehu.es/~etptupaf ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.