[R] How can I estimate a Box-Cox function with R?
Ikerne del Valle
ikerne.delvalle at ehu.es
Thu May 21 12:29:18 CEST 2009
Dear Fernando and all:
Thanks for your help. Now works. This is
a training example to learn how to estimate a
Box-Cox (right and/or left side transformations)
with R (as LIMDEP does) in order to compare these
estimations with the ones derived by applying
NLS, ones the dependent variable has been divided
by its geometric mean (see below) as suggested by
(Zarembka (1974) and Spitzer (1984). However the
example of the demand of money seems not to work.
Any idea to face the error messages or how to
estimate a Box-Cox function with R?
Best regards,
Ikerne
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)
Lr<-log(r)
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)
LM<-log(M)
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)
LY<-log(Y)
gmM<-exp((1/20)*sum(LM))
GM<-M/gmM
Gr<-r/gmM
GY<-Y/gmM
money<-data.frame(r,M,Y,Lr,LM,LY,GM,Gr,GY)
attach(money)
ols1<-lm(GM~r+Y)
output1<-summary(ols1)
coef1<-ols1$coefficients
a1<-coef1[[1]]
b11<-coef1[[2]]
b21<-coef1[[3]]
ols2<-lm(GM~Gr+GY)
output2<-summary(ols2)
coef2<-ols2$coefficients
a2<-coef2[[1]]
b12<-coef2[[2]]
b22<-coef2[[3]]
money.m1<-nls(GM~a+b*r^g+c*Y^g,data=money,start=list(a=a1,b=b11,g=1,c=b21))
money.m2<-nls(GM~a+b*Gr^g+c*GY^g,data=money,start=list(a=a2,b=b12,g=1,c=b22))
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
More information about the R-help
mailing list