楼主: redshoe04
19085 11

[问答] 想用R做个contour plot(等高线).不知道怎么做. [推广有奖]

11
maxili1983 发表于 2013-5-26 16:15:05
*
* GCONTOUR.RPF
* RATS Version 8, Introduction, Example from Section 4.13.
*
* Create a series which is mean 0 through entry 50, and mean 10 from 51
* through the end of the sample. We use a SEED to ensure that the graph
* can be reproduced
*
seed 95035
all 100
set x = %if(t>50,10,0)+%ran(1.0)
*
* The sum of squared residuals for a break between B and B+1 and a
* post-break mean of mu (pre-break mean assumed to be zero) is
*
*   sum (all t) of x^2 - 2*mu*sum (t>B) of x + (T-B)*mu^2
*
* This generates a contour plot of the concentrated log likelihood,
* assuming Normal residuals, and fixed, but unknown, variance.
*
* Set up the grids for breaks (1,...,100) and mus (.2,.4,...,20)
*
compute breaks=%seqa(1.0,1.0,100)
compute mus   =%seqa( .2, .2,100)
*
* This generates as "over" the sum of x for elements above t.
*
acc x / ax
set over = ax(100)-ax(t)
*
* Compute the sum of squares
*
compute x2=%normsqr(x)
*
* Generate the log likelihood for all the combinations of mus and breaks.
*
dec rect f(100,100)
ewise f(i,j)=-50.0*log((x2-2*mus(i)*over(fix(breaks(j)))+(100-breaks(j))*mus(i)^2)/100.0)
*
* Do the contour graph with a grid line across the actual break (50)
*
gcontour(x=mus,y=breaks,f=f,vgrid=||1||)


12
redshoe04 发表于 2013-8-31 13:36:33
谢谢

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 07:10