Dear all, For estimating Cobb-Douglad production Function [ Y = ALPHA * (L^(BETA1)) * (K^(BETA2)) ], i want to use nls function (without linearizing it). But how can i get initial values? ------------------------------------ > options(prompt=" R> " ) R> Y <- c(59.6, 63.9, 73.5, 75.6, 77.3, 82.8, 83.6, 84.9, 90.3, 80.5, 73.5, 60.3, 58.2, 64.4, 75.4, 85, 92.7, 85.4, 92.3, 101.2, 113.3, 107.8, 105.2, 107.1, 108.8, 131.4, 130.9, 134.7, 129.1, 147.8, 152.1, 154.3, 159.9) # production R> L <- c(39.4, 41.4, 43.9, 43.3, 44.5, 45.8, 45.9, 46.4, 47.6, 45.5, 42.6, 39.3, 39.6, 42.7, 44.2, 47.1, 48.2, 46.4, 47.8, 49.6, 54.1, 59.1, 64.9, 66, 64.4, 58.9, 59.3, 60.2, 58.7, 60, 63.8, 64.9, 66) # employment R> K <- c(236.2, 240.2, 248.9, 254.5, 264.1, 273.9, 282.6, 290.2, 299.4, 303.3, 303.4, 297.1, 290.1, 285.4, 287.8, 292.1, 300.3, 301.4, 305.6, 313.3, 327.4, 339, 347.1, 353.5, 354.1, 359.4, 359.3, 365.2, 363.2, 373.7, 386, 396.5, 408) # capital R> klein <- cbind(Y,L,K) R> klein.data<-data.frame(klein) R> coef(lm(log(Y)~log(L)+log(K))) # i used these linearized model's estimated parameters as initial values (Intercept) log(L) log(K) -3.6529493 1.0376775 0.7187662 R> nls(Y~ALPHA * (L^(BETA1)) * (K^(BETA2)), data=klein.data, start = c(ALPHA=-3.6529493,BETA1=1.0376775,BETA2=0.7187662), trace = T) 6852786785 : -3.6529493 1.0376775 0.7187662 1515217 : -0.02903916 1.04258165 0.71279051 467521.8 : -0.02987718 1.67381193 -0.05609925 346945.7 : -0.5570735 10.2050667 -10.2087997 Error in numericDeriv(form[[3]], names(ind), env) : Missing value or an Infinity produced when evaluating the model ------------------------------------ 1. What went wrong? I think the initial values are not good enough: How can i make a grid search? 2. How can i estimate C.E.S Production Function [ Y = GAMA * ((DELTA*K^(-BETA)) + ((1-DELTA)*L^(-BETA)))^(-PHI/BETA) ] using the same data? How to get the initial value? N.B.: The data file is available at http://www.angelfire.com/ab5/get5/klein.txt Any response / help / comment / suggestion / idea / web-link / replies will be greatly appreciated. Thanks in advance for your time. _______________________ Mohammad Ehsanul Karim <wildscop at yahoo.com> Institute of Statistical Research and Training University of Dhaka, Dhaka- 1000, Bangladesh
Mohammed,> For estimating Cobb-Douglas production Function [ Y = ALPHA * > (L^(BETA1)) * (K^(BETA2)) ], i want to use nls function > (without linearizing it). But how can i get initial values?This might be a dumb question, but why do you need nonlinear regression for that model? It is linear after taking logs: log Y = log ALPHA + BETA1 log L + BETA2 log K> 2. How can i estimate C.E.S Production Function [ Y = GAMA * > ((DELTA*K^(-BETA)) + ((1-DELTA)*L^(-BETA)))^(-PHI/BETA) ]Your second model (C.E.S. Prod. Fcn) does indeed look nonlinear, and I'm sorry I can't think how to find a good point around which to linearize. Can you guess some approximate parameter values for some "typical" Y,L,K data? If it's too hard to estimate parameters for a model, maybe it's time to come up with a new model :) Regards, James
WilDscOp wrote:> Dear all, > > For estimating Cobb-Douglad production Function [ Y = ALPHA * > (L^(BETA1)) * (K^(BETA2)) ], i want to use nls function (without > linearizing it). But how can i get initial values? > > ------------------------------------ > > options(prompt=" R> " ) > R> Y <- c(59.6, 63.9, 73.5, 75.6, 77.3, 82.8, 83.6, 84.9, 90.3, 80.5, > 73.5, 60.3, 58.2, 64.4, 75.4, 85, 92.7, 85.4, 92.3, 101.2, 113.3, 107.8, > 105.2, 107.1, 108.8, 131.4, 130.9, 134.7, 129.1, 147.8, 152.1, 154.3, > 159.9) # production > R> L <- c(39.4, 41.4, 43.9, 43.3, 44.5, 45.8, 45.9, 46.4, 47.6, 45.5, > 42.6, 39.3, 39.6, 42.7, 44.2, 47.1, 48.2, 46.4, 47.8, 49.6, 54.1, 59.1, > 64.9, 66, 64.4, 58.9, 59.3, 60.2, 58.7, 60, 63.8, 64.9, 66) # employment > R> K <- c(236.2, 240.2, 248.9, 254.5, 264.1, 273.9, 282.6, 290.2, > 299.4, 303.3, 303.4, 297.1, 290.1, 285.4, 287.8, 292.1, 300.3, 301.4, > 305.6, 313.3, 327.4, 339, 347.1, 353.5, 354.1, 359.4, 359.3, 365.2, > 363.2, 373.7, 386, 396.5, 408) # capital > R> klein <- cbind(Y,L,K) > R> klein.data<-data.frame(klein) > R> coef(lm(log(Y)~log(L)+log(K))) > # i used these linearized model's estimated parameters as initial values > (Intercept) log(L) log(K) > -3.6529493 1.0376775 0.7187662 > R> nls(Y~ALPHA * (L^(BETA1)) * (K^(BETA2)), data=klein.data, start = > c(ALPHA=-3.6529493,BETA1=1.0376775,BETA2=0.7187662), trace = T) > 6852786785 : -3.6529493 1.0376775 0.7187662 > 1515217 : -0.02903916 1.04258165 0.71279051 > 467521.8 : -0.02987718 1.67381193 -0.05609925 > 346945.7 : -0.5570735 10.2050667 -10.2087997 > Error in numericDeriv(form[[3]], names(ind), env) : > Missing value or an Infinity produced when evaluating the model > ------------------------------------ > > 1. What went wrong? I think the initial values are not good enough: How > can i make a grid search? >I think you meant this: nls(Y~ALPHA * (L^(BETA1)) * (K^(BETA2)), data=klein.data, start = c(ALPHA=exp(-3.6529493),BETA1=1.0376775,BETA2=0.7187662), trace = TRUE) Note that you neglected to exponentiate ALPHA.> 2. How can i estimate C.E.S Production Function [ Y = GAMA * > ((DELTA*K^(-BETA)) + ((1-DELTA)*L^(-BETA)))^(-PHI/BETA) ] using the > same data? How to get the initial value? >This one is tougher. I set initial values DELTA = 0.5 and BETA = -1 and solved the log(Y) problem. # log(Y) = log(GAMMA) + PHI * log(0.5 * K + 0.5 * L) DELTA <- 0.5 BETA <- -1.0 start <- coef(lm(log(Y) ~ log(I(0.5 * K + 0.5 * L)))) GAMMA <- exp(start[1]) PHI <- -BETA * start[2] However, I still couldn't get nls to even take one step due to singular gradient at the initial values. So I tried optim instead ces.opt <- function(par, Y, L, K) { delta <- par[1] beta <- par[2] gamma <- par[3] phi <- par[4] Y0 <- delta * K^(-beta) + (1 - delta) * L^(-beta) Yhat <- gamma * Y0^(-phi/beta) sum((Y - Yhat)^2) } start <- optim(c(DELTA, BETA, GAMMA, PHI), ces.opt, Y = Y, L = L, K = K, method = "BFGS", control = list(maxit = 1000)) Y0hat <- with(start, par[1] * K^(-par[2]) + (1 - par[1]) * L^(-par[2])) Yhat <- with(start, par[3] * Y0hat^(-par[4]/par[2])) plot(Yhat ~ Y) The fit wasn't to shabby. So I used the final values from the output from optim to feed to nls. nls(Y ~ GAMMA * (DELTA * K^(-BETA) + (1 - DELTA) * L^(-BETA))^(-PHI/BETA), data=klein.data, start = c(DELTA = start$par[1], BETA = start$par[2], GAMMA = start$par[3], PHI = start$par[4]), trace = TRUE) This still didn't work. Perhaps somebody else can explain this, though. HTH, --sundar
Mohammad Ehsanul Karim
2004-Apr-18 07:28 UTC
[R] Non-Linear Regression (Cobb-Douglas and C.E.S)
Dear James Wettenhall, Your question - why do i need nonlinear regression for that model when it is linear after taking logs - is not a dumb question: rather it is a rational one. Actually C.E.S Production Function [ Y = GAMA * ((DELTA*K^(-BETA)) + ((1-DELTA)*L^(-BETA)))^(-PHI/BETA) ] is my main concern (In this case there is no way to linearize it), the Cobb-Douglas being just a 'Toy problem' to see how non-linear process works. And i'm sorry that i cannot guess some approximate parameter values for that CES using some "typical" Y,L,K data : that why it is a problem (doing a grid search over infinite parameter space is indeed time consuming). Thanks in advance for your time and effort - and sorry for my late reply. _______________________ Mohammad Ehsanul Karim <appstat at HotPOP.com> Institute of Statistical Research and Training University of Dhaka, Dhaka- 1000, Bangladesh
Mohammad Ehsanul Karim
2004-Apr-18 07:40 UTC
[R] Non-Linear Regression (Cobb-Douglas and C.E.S)
Dear Sundar Dorai-Raj, Thank you very much for mentioning to exponentiate ALPHA. However, so far i understand that the parameters in the non-linear equation Y = ALPHA * (L^(BETA1)) * (K^(BETA2)) and the coefficients of log(L) and log(K) of the following equation (after linearizing) log(Y) = log(ALPHA) +(BETA1)*log(L) + (BETA2)*log(K) should be the same when estimated from either equation. Is it true? If it is, then why the estimates of the two procedure (see below) are different? Can you please explain it? ----------------------------- > coef(lm(log(Y)~log(L)+log(K), data=klein.data)) (Intercept) log(L) log(K) -3.6529493 1.0376775 0.7187662 ----------------------------- > nls(Y~ALPHA * (L^(BETA1)) * (K^(BETA2)), data=klein.data, start = c(ALPHA=exp(-3.6529493),BETA1=1.0376775,BETA2 = 0.7187662), trace = TRUE) Nonlinear regression model model: Y ~ ALPHA * (L^(BETA1)) * (K^(BETA2)) data: klein.data ALPHA BETA1 BETA2 0.003120991 0.414100040 1.513546235 residual sum-of-squares: 3128.245 ----------------------------- Thanks in advance for your time and effort - and sorry for my late reply. _______________________ Mohammad Ehsanul Karim <appstat at HotPOP.com> Institute of Statistical Research and Training University of Dhaka, Dhaka- 1000, Bangladesh
> Dear all, > > For estimating Cobb-Douglad production Function [ Y = ALPHA * > (L^(BETA1)) * > (K^(BETA2)) ], i want to use nls function (without > linearizing it). But > how can i get initial values? > > ------------------------------------ > > options(prompt=" R> " ) > R> Y <- c(59.6, 63.9, 73.5, 75.6, 77.3, 82.8, 83.6, 84.9, > 90.3, 80.5, > 73.5, 60.3, 58.2, 64.4, 75.4, 85, 92.7, 85.4, 92.3, 101.2, > 113.3, 107.8, > 105.2, 107.1, 108.8, 131.4, 130.9, 134.7, 129.1, 147.8, 152.1, 154.3, > 159.9) # production > R> L <- c(39.4, 41.4, 43.9, 43.3, 44.5, 45.8, 45.9, 46.4, > 47.6, 45.5, > 42.6, 39.3, 39.6, 42.7, 44.2, 47.1, 48.2, 46.4, 47.8, 49.6, > 54.1, 59.1, > 64.9, 66, 64.4, 58.9, 59.3, 60.2, 58.7, 60, 63.8, 64.9, 66) # > employment > R> K <- c(236.2, 240.2, 248.9, 254.5, 264.1, 273.9, 282.6, > 290.2, 299.4, > 303.3, 303.4, 297.1, 290.1, 285.4, 287.8, 292.1, 300.3, 301.4, 305.6, > 313.3, 327.4, 339, 347.1, 353.5, 354.1, 359.4, 359.3, 365.2, > 363.2, 373.7, > 386, 396.5, 408) # capital > R> klein <- cbind(Y,L,K) > R> klein.data<-data.frame(klein) > R> coef(lm(log(Y)~log(L)+log(K))) > # i used these linearized model's estimated parameters as > initial values > (Intercept) log(L) log(K) > -3.6529493 1.0376775 0.7187662 > R> nls(Y~ALPHA * (L^(BETA1)) * (K^(BETA2)), > data=klein.data, start = > c(ALPHA=-3.6529493,BETA1=1.0376775,BETA2=0.7187662), trace = T) > 6852786785 : -3.6529493 1.0376775 0.7187662 > 1515217 : -0.02903916 1.04258165 0.71279051 > 467521.8 : -0.02987718 1.67381193 -0.05609925 > 346945.7 : -0.5570735 10.2050667 -10.2087997 > Error in numericDeriv(form[[3]], names(ind), env) : > Missing value or an Infinity produced when > evaluating the model > ------------------------------------ > > 1. What went wrong? I think the initial values are not good > enough: How can > i make a grid search? > > 2. How can i estimate C.E.S Production Function [ Y = GAMA * > ((DELTA*K^(-BETA)) + ((1-DELTA)*L^(-BETA)))^(-PHI/BETA) ] > using the same > data? How to get the initial value? >Dear James, Wettenhall, as far as the CES production function is concerned, you might want to utilise the Kmenta approximation. The following link elucidates this approach and other feasible estimation techniques. http://www.cu.lu/crea/projets/mod-L/prod.pdf HTH, Bernhard> N.B.: The data file is available athttp://www.angelfire.com/ab5/get5/klein.txt Any response / help / comment / suggestion / idea / web-link / replies will be greatly appreciated. Thanks in advance for your time. _______________________ Mohammad Ehsanul Karim <wildscop at yahoo.com> Institute of Statistical Research and Training University of Dhaka, Dhaka- 1000, Bangladesh ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -------------------------------------------------------------------------------- The information contained herein is confidential and is inte...{{dropped}}