Docsity

Computational Tools for Economics, Esercizi di Econometria

Anteprima parziale del testo

Scarica Computational Tools for Economics e più Esercizi in PDF di Econometria solo su Docsity!

attempt

[1] 2 4

[1] 1 2 3 4

l <- function (x)-x+ 2 p <- function (x)x^2-2*x+ 4 curve(l,- 2 , 1 ) curve(p,- 2 , 1 ,add=T) optimize(l,c(- 2 , 1 )) $minimum [1] 0. $objective [1] 1. optimize(p,c(- 2 , 1 ))

$minimum [1] 0. $objective [1] 3 x <- 1 : 10 y <- 2.5sin(29.9x) plot(x,y) abline(2.5,-0.5) abline(- 3 , 1 ) abline(h=- 2 ) f <- function (p)4.5exp(2.5p)-0.6*exp( 3 *p) curve(f,- 10 , 10 ,ylim=c( 0 , 100 )) abline(v=2.97,col= 3 )

uniroot(d,c( 20 , 30 )) $root [1] 22. $f.root [1] -2.639657e- $iter [1] 6 $init.it [1] NA $estim.prec [1] 6.103516e- exper <- function () { x1 <- rnorm( 1 ,0.04,0.12) x2 <- rnorm( 1 ,0.04,0.12) x3 <- rnorm( 1 ,0.04,0.12) return( 1000 ( 1 +x1)( 1 +x2)*( 1 +x3)) }

res <- replicate( 1000 ,exper()) mean(res< 1100 ) [1] 0. f <- function (x,y)(y^2-5)^ 2 +x^ 2 + 1 +x*y+x x <- seq(- 3 , 3 ,len= 100 ) y <- seq(-2.5,2.5,len= 100 ) z <- outer(x,y,f) image(x,y,z) contour(x,y,z,add=T) fb <- function (x)f(x[ 1 ],x[ 2 ]) optim(c( 1 ,-2.5),fb) $par [1] 0.6257887 -2. $value [1] 0. $counts function gradient 53 NA

constrOptim(c( 2 , 2 ),fb,NULL,A,b,control=list(fnscale=- 1 )) $par [1] 0.8703255 0. $value [1] -8. $counts function gradient 258 NA $convergence [1] 0 $message NULL $outer.iterations [1] 3 $barrier.value [1] 0.

A <- matrix(c( 106 , 106 , 106 , 92 , 93 , 98 , 115 ,116.8,119.8), 3 , 3 ) pai <- c(95.4,84.7,105.12) x <- solve(A,A[, 3 ]) A%%x [,1] [1,] 115. [2,] 116. [3,] 119. sum(paix) #NBBBBBB [1] 105. f <- function (x,y)x^ 2 +y^ 2 +xy+ 2 x-3y exper <- function () { x <- runif( 1 ) y <- runif( 1 ) z <- f(x,y) return(z> 0 &z< 2 ) } res <- replicate( 1000 ,exper()) mean(res) [1] 0. exper <- function () { x <- runif( 1 , 0 , 3 ) y <- runif( 1 , 0 , 2 ) return(y>0.5x) } res <- replicate( 1000 ,exper()) mean(res) [1] 0.

Quarto

Quarto enables you to weave together content and executable code into a

finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that

includes both content and the output of embedded code. You can embed

code like this:

[1] 2

You can add options to executable code like this