graphing confidence bands

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

vogelh
Posts: 35
Joined: Mon May 21, 2012 2:27 pm

graphing confidence bands

Postby vogelh » Wed Jul 25, 2012 1:15 pm

Using eviews 7.
Have estimated a simple regression line with 2 variables, have output as scatter diagram with regression line thru middle.
Is there a simple way to graph confidence interval (95% or other) bands?
Thanks.
HV

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

Re: graphing confidence bands

Postby EViews Esther » Wed Jul 25, 2012 2:26 pm

Please click the Forecast tab of the equation dialog.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: graphing confidence bands

Postby EViews Glenn » Wed Jul 25, 2012 2:37 pm

Which will do the graph in observation order but not scatterplot order. For the scatterplot, you'll have to add the lines yourself...

vogelh
Posts: 35
Joined: Mon May 21, 2012 2:27 pm

Re: graphing confidence bands

Postby vogelh » Wed Jul 25, 2012 2:59 pm

looks like I'll have to do it myself for scatter plot. I see the banks in observation order using forecast.
Perhaps EViews can add this as an option to future updates.

Is there an easy way to generate the confidence bands via formula/equation?
thanks.

vogelh
Posts: 35
Joined: Mon May 21, 2012 2:27 pm

Re: graphing confidence bands

Postby vogelh » Wed Jul 25, 2012 3:43 pm

looks like I'll have to do it myself for scatter plot. I see the banks in observation order using forecast.
Perhaps EViews can add this as an option to future updates.

Is there an easy way to generate the confidence bands via formula/equation?
thanks.

startz
Non-normality and collinearity are NOT problems!
Posts: 3798
Joined: Wed Sep 17, 2008 2:25 pm

Re: graphing confidence bands

Postby startz » Wed Jul 25, 2012 3:51 pm

In the Forecast dialog there is a field to specify a new series to contain the standard error of the forecast. So is you name the forecast yf and the standard error yse, you can generate

Code: Select all

series upper= yf + 1.96*yse series lower = yf - 1.96*yse
Except you need to substitute an appropriate critical value in place of 1.96. Then do a scatterplot of x against upper, yf, lower.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: graphing confidence bands

Postby EViews Glenn » Wed Jul 25, 2012 4:27 pm

The one issue is that unless the workfile is X-sorted, you won't be able to connect the observations with lines to show the band in the usual way. If it's not a time-series workfile, sorting by X is an option.

One issue with providing it as a built-in is that it's only really applicable to bivariate models which I would venture are a small subset of the models estimate. But I do think that it's a natural one for an add-in.

startz
Non-normality and collinearity are NOT problems!
Posts: 3798
Joined: Wed Sep 17, 2008 2:25 pm

Re: graphing confidence bands

Postby startz » Wed Jul 25, 2012 5:39 pm

The one issue is that unless the workfile is X-sorted, you won't be able to connect the observations with lines to show the band in the usual way. If it's not a time-series workfile, sorting by X is an option.
No, scatter takes care of the ordering, although you may have to mess with the Graph elements/lines and symbols dialog.
One issue with providing it as a built-in is that it's only really applicable to bivariate models which I would venture are a small subset of the models estimate. But I do think that it's a natural one for an add-in.
But extraordinarily handy for teaching purposes.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: graphing confidence bands

Postby EViews Gareth » Wed Jul 25, 2012 7:53 pm

I think Glenn is right, you do need the sorting. It is not essential, but the graph will look much better if you have the sorting in place. Especially if you have a nonlinear estimation. Moving into matrix space rather than dealing with workfile sorting is probably easiest.

I'm not in the office, so knocked up this program on my iPhone. No guarantees it doesn't have mistakes in it, since I can't test it on my phone. Hopefully if there are some, they'll be easy to spot.

Open up your equation, then run the program, or register it as an add-in.

Code: Select all

%fn = @getnextname("yf") %sen = @getnextname("se") %mn = @getnextname("fitmat") %gn = @getnextname("g") %grn = @getnextname("gr") %xn = @getnextname("x") %rn = @getnextname("ranks") _this.fit {%fn} {%sen} %varlist = _this.@varlist if @wcount(%varlist) <> 3 then @uiprompt("Equation doesn't have 2 regressors") stop endif %dep = @word(%varlist,1) %reg = @word(%varlist,3) if %reg = "C" then %reg = @word(%varlist,2) endif group {%gn} {%reg} {%dep} {%fn} {%fn}+1.96*{%sen} {%fn}-1.96*{%sen} stom({%gn}, {%mn}) stom({%reg}, {%xn}) vector {%rn} = @ranks({%xn}) {%mn} = @capplyranks({%mn}, {%rn}) freeze({%grn}) {%mn}.scat %depstr = "Fitted " + %dep %lowstr = "Lower bound" %uppstr = "Upper bound" {%grn}.setelem(1) symbol(circle) linecolor(blue) legend(%dep) {%grn}.setelem(2) symbol(none) lpat(1) linecolor(red) legend(%depstr) {%grn}.setelem(3) symbol(none) lpat(1) linecolor(green) legend(%uppstr) {%grn}.setelem(4) symbol(none) lpat(1) linecolor(green) legend(%uppstr) show {%grn} d(noerr) {%fn} {%sen} {%mn} {%gn} {%xn} {%rn}

startz
Non-normality and collinearity are NOT problems!
Posts: 3798
Joined: Wed Sep 17, 2008 2:25 pm

Re: graphing confidence bands

Postby startz » Wed Jul 25, 2012 8:40 pm

Code: Select all

create u 200 series x=nrnd series y=2+3*x+nrnd equation eq eq.ls y c x eq.fit yf yse scat x yf yf-1.96*yse yf+1.96*yse
Then by hand change from symbols to lines.
foo.png
foo.png (14.65 KiB) Viewed 13983 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: graphing confidence bands

Postby EViews Gareth » Wed Jul 25, 2012 9:47 pm

Notice how those lines are thick and inconsistent? That's because the same line is being drawn over itself many times. Since it is a straight line, it doesn't matter so much, but I think it is still ugly. Try running my program on it, and you should get a nicer looking graph.

Further, try changing yours so that there is a non-linearity in there, or try estimating log(y) c x. Bet it doesn't look as good then.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: graphing confidence bands

Postby EViews Glenn » Thu Jul 26, 2012 10:53 am

In Gareth's example, I had to change the @ranks function call to be

Code: Select all

vector {%rn} = @ranks({%xn}, "a", "i")
so that we didn't get fractional ranks on tied values. Also the labeling on the legend isn't quite right

Code: Select all

{%grn}.setelem(3) symbol(none) lpat(1) linecolor(green) legend(%lowstr)
There are a few more minor things as well that I'll leave as a further exercise. This is a nice proof of concept that needs a bit more cleanup.


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 2 guests