全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 LATEX论坛
1690 2
2016-10-18
By arthur charpentier


Just a short post, to share some codes used to generate animated graphs, with R. Assume that we would like to illustrate the law of large number, and the convergence of the average value from binomial sample. We can generate samples using

复制代码

Each row will be a trajectory of heads and tails. For each trajectory, define the mean , which will denote the mean of the first values. Such a matrix can be computed using

复制代码

Define then

复制代码

Now, to generate an animated gif, the way I usually do it is to generate graphs (png graphs) using a loop,

复制代码

I start at 100 because afterwards, when merging files, it is better to have (really) consecutive numbers, since sometimes, the lexical order is used, i.e. after 1 is 10, then 100, etc. Then I use Terminal commands




Here, the delay is in /100 seconds, and I use an infinite loop. The graph is here



It is possible to use

复制代码

But the loop can be used also to generate several graphs, and to produce an animated graph in a pdf document (slides or lecture notes). The idea is to use the same code, but the output is here a pdf graph.

复制代码

We can then import them in LaTeX,

复制代码

This will generate the following pdf file. This animate package is described in several forums, e.g. http://www.geogebra.org/…


Arthur CharpentierArthur Charpentier, professor in Montréal, in Actuarial Science. Former professor-assistant at ENSAE Paristech, associate professor at Ecole Polytechnique and assistant professor in Economics at Université de Rennes 1.  Graduated from ENSAE, Master in Mathematical Economics (Paris Dauphine), PhD in Mathematics (KU Leuven),





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2019-4-30 16:34:09
谢谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-4-16 00:24:46
thx for sharing~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群