File: bin_use.q

package info (click to toggle)
sm 2.0.14-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 992 kB
  • ctags: 26
  • sloc: fortran: 133; sh: 28; makefile: 13
file content (38 lines) | stat: -rw-r--r-- 942 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# example of use of binning

cat("Examples of use of function binning()\n")

#    1-d example

x  <- rnorm(1000)
xb <-binning(x)
h  <-hnorm(x)
sm.density(xb$x, h=h, weights=xb$x.freq, ylim=c(0,0.5/sqrt(var(x))))
pause()

#     2-d example

x  <-cbind(x,x+rnorm(1000))
xb <-binning(x)
h  <-hnorm(x)
par(mfrow=c(1,2))
sm.density(xb$x, h=h, weights=xb$x.freq)
sm.density(xb$x, h=h, weights=xb$x.freq, display="slice")
par(mfrow=c(1,1))
pause()

#      and another

provide.data(airpc)
pc3    <- cbind(Comp.1, Comp.2)[Period==3,]
pc.bin <- binning(pc3)
par(mfrow=c(1,2))
sm.density(pc.bin$x, h = hnorm(pc3), display = "image", ngrid=100,
          weights=pc.bin$x.freq)
plot(pc3, xlab="First Principal Component", ylab="Second Principal Component")
cat("this time original data rather than grid data are plotted\n")
sm.density(pc.bin$x, h = hnorm(pc3), display = "slice", ngrid=30,
          add=TRUE, weights=pc.bin$x.freq)
par(mfrow=c(1,1))