Throughout the Tutorials we use XploRe example code which can be directly typed into the command line. We have seen this in the previous sections when calculating the mean and creating the scatter plot for the pullover data.
Since it can be cumbersome to type many lines of code, we
summarized instructions that belong together into quantlet
files. These quantlet files are either displayed within the
text, as e.g.
XLGstart01.xpl
or printed at the end
of a sequence of instructions:
x=read("pullover") ; reads data x=x[,2|1] library("plot") plot(x) ; shows scatter plot
\
XploRe, you can find the examples
in C:\
XploRe\
examples.
To load an example quantlet, use the Open item from the
Program menu. Change the directory to examples
and double-click on the appropriate file. This opens an
editor window containing the example code.
We execute the quantlet
by clicking the Execute item in the menu bar
or by entering Alt E
.
Quantlets contain one XploRe instruction in each line. Additionally, it is possible to add comments. For example, in
x = 1 ; assign the value 1 to x y = 2 // assign the value 2 to yeverything beyond the ; and // is a comment. You can also use /* and */ to mark the beginning and the end of several lines of comments.
The following subsections intend to give you an impression of the capabilities of XploRe . We will present some of the statistical methods that are explained in detail later on.
XploRe
has several functions to print summary statistics
of all columns of a data file. The following example
uses the function
summarize
from the
stats
library:
library("stats") x=read("pullover") library("stats") setenv("outputstringformat","%s") summarize(x, "sales"|"price"|"ads"|"assistance")
Contents of summ [1,] [2,] Minimum Maximum Mean Median Std.Error [3,] ----------------------------------------------- [4,] sales 97 230 172.7 172 33.948 [5,] price 80 125 104.6 99 15.629 [6,] ads 0 200 104 105 53.996 [7,] assistance 71 111 93.8 93 14.038 [8,]You will learn more about summary statistics in Descriptive Statistic (2).
A histogram visualizes univariate data. Hence, we produce separate histograms for the variables (columns) of a data matrix. The following example shows the histogram for the sixth column (diagonal length) of the Swiss bank notes data stored in the file bank2.dat (see Data Sets (B.7).)
library("plot") y=read("bank2") y=y[,6] library("plot") setsize(640,480) ; sets display size plothist(y) ; plots histogram
The method of kernel density estimation allows us to estimate the distribution of data in a very flexible way. We introduce this topic in Smoothing Methods (6). Here we compute the density estimate for the joint density of the upper frame length and the diagonal length (fifth and sixth variable) of the bank2 data (see Data Sets (B.7))
library("smoother") library("plot") x = read("bank2") x=x[,5:6] library("smoother") library("plot") fh = denxestp(x) ; density estimation fh = setmask(fh,"surface","blue") setsize(640,480) axesoff() cu = grcube(fh) ; box plot(cu.box,cu.x,cu.y, fh) ; plot box and fh setgopt(plotdisplay,1,1,"title","2D Density Estimate") axeson()
The density estimate confirms our impression from Subsection 1.2.2 that the data set features two clusters.
XploRe is particularly suited for interactive use. The following quantlet computes a nonparametric regression smoother and asks interactively for the bandwidth.
proc()=interactive(x) error(cols(x)!=2,"x has more than 2 columns!") x=setmask(x,"red","cross") h=(max(x[,1])-min(x[,1]))/5 stop=0 while (stop!=1) mh=setmask(regxest(x,h),"line") plot(x,mh) hnew=readvalue("Bandwidth h (0 to stop)",h) while (hnew<0) hnew=readvalue("Bandwidth h (0 to stop)",h) endo if (hnew!=0) h=hnew else stop=1 endif endo endp library("plot") library("smoother") x=read("nicfoo") interactive(x)
Nonparametric smoothing is introduced in Smoothing Methods (6).
If you want to program interactive quantlets yourself,
we recommend that you study Quantlets and Quantlibs
(17).