R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("JLLprod-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('JLLprod') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Blocc" > > ### * Blocc > > flush(stderr()); flush(stdout()) > > ### Name: Blocc > ### Title: Fast Local Constant Regression for Bivariate Data > ### Aliases: Blocc > ### Keywords: smooth regression > > ### ** Examples > > #A very simple case > n <- 1000 > x <- runif(n); z <- runif(n); e <- rnorm(n,sd=0.2) > G <- function(x){(1/2)*sin(2*pi*x)} > F <- function(z){-1/3+2*z-2*(z^2)} > y <- G(x)+F(z) + e > xgrid <- seq(0,1,length=30); zgrid <- seq(0,1,length=30) > > m <- Blocc(xx=x,zz=z,yy=y,ev=cbind(xgrid,zgrid)) > GF <- matrix(G(m$xxe),nr=30,nc=30,byrow=FALSE)+matrix(F(m$zze) + ,nr=30,nc=30,byrow=TRUE) > > #win.graph() > layout(matrix(c(1,2),nr=1,nc=2,byrow=TRUE)) > persp(x=m$zze,y=m$xxe,z=t(GF),theta= 320, phi=17,xlab="z" + ,ylab="x",zlab="",main="True G(x)+F(z)") > persp(x=m$zze,y=m$xxe,z=t(m$r),theta= 320, phi=17,xlab="z" + ,ylab="x",zlab="",main="Estimated G(x)+F(z)") > > > > cleanEx(); ..nameEx <- "JLL" > > ### * JLL > > flush(stderr()); flush(stdout()) > > ### Name: JLL > ### Title: Generalized Homothetic Production Function: Main Estimator > ### Aliases: JLL > ### Keywords: smooth regression > > ### ** Examples > > #A simple simulation > d<- 1; n=400 > xx <- runif(n^d); zz <- runif(n^d); > x <- cbind(xx,zz) > e <- rnorm(n^d,sd=1) > G <- function(x){(1/2)*sin(2*pi*x)} > F <- function(z){-2*(z^2)+2*z-1/3} > M <- function(x,z){G(x)+F(z)} > H <- function(m){1+(16/7)*m} > z0<-1/4; r0<-H(0); > y <- H(M(x[,1],x[,2])) + e > m <- JLL(xx=x[,1],zz=x[,2],yy=y,p1=3,p2=1,pstar=1,h1=0.15,h2=0.7,ngrid=10, + z0=z0,r0=r0) > > #win.graph() > layout(matrix(c(1,2,1,2),2,2, byrow=TRUE),respect=TRUE) > plot(m$x,m$Ghat,type="l",lty=1) > lines(m$x,G(m$x),type="l",lty=2,col="blue") > plot(m$z,m$Fhat,type="l",lty=1) > lines(m$z,F(m$z),type="l",lty=2,col="blue") > > > > cleanEx(); ..nameEx <- "JLL.plot" > > ### * JLL.plot > > flush(stderr()); flush(stdout()) > > ### Name: JLL.plot > ### Title: Plots of Nonparametric Elements of a Generalized Homothetic > ### Production Function > ### Aliases: JLL.plot > ### Keywords: smooth > > ### ** Examples > > library(JLLprod) > data(ecu) > ##This part simply does some data sorting & trimming > xlnK <- ecu$lnk > xlnL <- ecu$lnl > xlnY <- ecu$lny > xqKL <- quantile(xlnK-xlnL, probs=c(2.5,97.5)/100) > yx <- cbind(xlnY,xlnK,xlnL) > tlnklnl <- yx[((yx[,2]-yx[,3])>=xqKL[1]) & ((yx[,2]-yx[,3])<=xqKL[2]),] > tlnklnl[,2]<-tlnklnl[,2]-tlnklnl[,3] > g<-seq(min(tlnklnl[,3]),max(tlnklnl[,3]),length=29) > > #This part does the actual calculations & plots > m.JLL <- JLL(xx=tlnklnl[,2],zz=tlnklnl[,3],yy=tlnklnl[,1],p1=2,p2=2, + pstar=0,h1=3.125,h2=5.25,ngrid=30,z0=g[25],r0=7.5) > JLL.plot(m.JLL) > > > > cleanEx(); ..nameEx <- "JLLp" > > ### * JLLp > > flush(stderr()); flush(stdout()) > > ### Name: JLLp > ### Title: Parametric Generalized Homothetic Production Function > ### Aliases: JLLp > ### Keywords: regression > > ### ** Examples > > library(JLLprod) > data(ecu) > ##This part simply does some data sorting & trimming > xlnK <- ecu$lnk > xlnL <- ecu$lnl > xlnY <- ecu$lny > xqKL <- quantile(xlnK-xlnL, probs=c(2.5,97.5)/100) > yx <- cbind(xlnY,xlnK,xlnL) > tlnklnl <- yx[((yx[,2]-yx[,3])>=xqKL[1]) & ((yx[,2]-yx[,3])<=xqKL[2]),] > tlnklnl[,2]<-tlnklnl[,2]-tlnklnl[,3] > > bb<-list(b0=11,b1=1,b2=0,g=-0.15,a=0.4) > Y <- tlnklnl[,1]; K <- tlnklnl[,2]; L <- tlnklnl[,3] > pJLL<-JLLp(Y,K,L,theta=bb,model=2) > print(summary(pJLL)) Formula: lnY ~ b0 + b1 * (a * lnk + log(exp(lnL) + g)) + b2 * (a * lnk + log(exp(lnL) + g))^2 Parameters: Estimate Std. Error t value Pr(>|t|) b0 6.96420 1.99646 3.488 0.000543 *** b1 0.04620 0.51711 0.089 0.928861 b2 0.09922 0.03812 2.603 0.009608 ** g -558.04861 198.04679 -2.818 0.005089 ** a 0.30006 0.03676 8.164 4.87e-15 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.7325 on 379 degrees of freedom Correlation of Parameter Estimates: b0 b1 b2 g b1 B 1 b2 B B 1 g + , , 1 a , . , , attr(,"legend") [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1 > > > > cleanEx(); ..nameEx <- "LL" > > ### * LL > > flush(stderr()); flush(stdout()) > > ### Name: LL > ### Title: Homothetic Production Function: Main Estimator > ### Aliases: LL > ### Keywords: smooth regression > > ### ** Examples > > > data(ecu) > ##This part simply does some data sorting & trimming > xlnK <- ecu$lnk > xlnL <- ecu$lnl > xlnY <- ecu$lny > xqKL <- quantile(exp(xlnK)/exp(xlnL), probs=c(2.5,97.5)/100) > yx <- cbind(xlnY,xlnK,xlnL) > tlnklnl <- yx[((exp(yx[,2])/exp(yx[,3]))>=xqKL[1]) + & ((exp(yx[,2])/exp(yx[,3]))<=xqKL[2]),] > Y<-tlnklnl[,1] > K<-exp(tlnklnl[,2])/median(exp(tlnklnl[,2])) > L<-exp(tlnklnl[,3])/median(exp(tlnklnl[,3])) > > LLb<-LL(xx=K,zz=L,yy=Y,xxo=median(K),zzo=median(L),k=80,j=100) > > #win.graph() > nf <- layout(matrix(c(1,2,1,2),2,2, byrow=TRUE),respect=TRUE) > plot(log(K)-log(L),log(LLb$g)-log(L),pch=3,xlab="ln(K/L)" + ,ylab="ln(g(K/L,1))",main="Homogeneous Component g") > plot(log(LLb$g),LLb$h,xlab="ln(g)",pch=3,ylab="h(g)" + ,main="Nonhomogeneous Component h",ylim=c(min(min(LLb$h) + ,min(LLb$r)),max(max(LLb$h),max(LLb$r)))) > points(log(LLb$g),LLb$r,type="p",pch=1,col="blue",lwd=2) > legend(-0.5,15.5,c("Nonparametric","Kernel Regression") + ,merge=TRUE,lty=c(1,-1),pch=c(3,1),lwd=c(1,2) + ,col=c("black","blue"),cex=0.95) > > > > cleanEx(); ..nameEx <- "LLef" > > ### * LLef > > flush(stderr()); flush(stdout()) > > ### Name: LLef > ### Title: Homothetic Production Function: Most Efficient Estimator > ### Aliases: LLef > ### Keywords: smooth regression > > ### ** Examples > > > data(ecu) > ##This part simply does some data sorting & trimming > xlnK <- ecu$lnk > xlnL <- ecu$lnl > xlnY <- ecu$lny > xqKL <- quantile(exp(xlnK)/exp(xlnL), probs=c(2.5,97.5)/100) > yx <- cbind(xlnY,xlnK,xlnL) > tlnklnl <- yx[((exp(yx[,2])/exp(yx[,3]))>=xqKL[1]) + & ((exp(yx[,2])/exp(yx[,3]))<=xqKL[2]),] > Y<-tlnklnl[,1] > K<-exp(tlnklnl[,2])/median(exp(tlnklnl[,2])) > L<-exp(tlnklnl[,3])/median(exp(tlnklnl[,3])) > > LLb<-LL(xx=K,zz=L,yy=Y,xxo=median(K),zzo=median(L),k=80,j=100) > LLbef <- LLef(xx=K,zz=L,yy=Y,h0=1,LLob=LLb) > > #win.graph() > nf <- layout(matrix(c(1,2,1,2),2,2, byrow=TRUE),respect=TRUE) > plot(log(K)-log(L),log(LLbef$gef)-log(L),pch=3,xlab="ln(K/L)" + ,ylab="ln(g(K/L,1))",main="Homogeneous Component g") > plot(log(LLbef$gef),LLbef$hef,xlab="ln(g)",pch=3,ylab="h(g)" + ,main="Nonhomogeneous Component h",ylim=c(min(min(LLbef$hef) + ,min(LLb$r)),max(max(LLbef$hef),max(LLb$r)))) > points(log(LLbef$gef),LLb$r,type="p",pch=1,col="blue",lwd=2) > legend(-0.5,15.6,c("Nonparametric","Kernel Regression") + ,merge=TRUE,lty=c(1,-1),pch=c(3,1),lwd=c(1,2) + ,col=c("black","blue"),cex=0.95) > > > > cleanEx(); ..nameEx <- "ecu" > > ### * ecu > > flush(stderr()); flush(stdout()) > > ### Name: ecu > ### Title: Production Data: Ecuador (2002) > ### Aliases: ecu > ### Keywords: datasets > > ### ** Examples > > data(ecu) > #some plots > #win.graph() > layout(matrix(c(1,2,1,2),2,2, byrow=TRUE),respect=TRUE) > plot(ecu$lnk-ecu$lnl,ecu$lny,xlab="ln(K/L)",ylab="ln(y)",main="") > plot(ecu$lnl,ecu$lny,xlab="ln(L)",ylab="ln(y)",main="") > par(oma=c(1,1,1.85,1),new=TRUE,font=2,cex=1) > mtext(outer=TRUE,"Petroleum, Chemical & Plastics - 2002",side=3,cex=1) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "locpoly" > > ### * locpoly > > flush(stderr()); flush(stdout()) > > ### Name: locpoly > ### Title: Local Polynomial Regression > ### Aliases: locpoly > ### Keywords: smooth regression > > ### ** Examples > > #A very simple case > n <- 5000 > x <- runif(n); e <- rnorm(n,sd=1) > G <- function(x){(1/2)*sin(2*pi*x)} > y <- G(x) + e > xgrid <- seq(0,1,length=30) > m <- locpoly(y=y,x=x,h=0.08,p=1,targmat=xgrid,der=0,nobmin=5,kernel="gauss") > plot(xgrid,G(xgrid),xlab="x",ylab="G",main="",col="black",type="l",lty=1) > lines(xgrid,m$yhat,col="red",type="l",lty=2) > > > > ### *