File: cobar.R

package info (click to toggle)
r-cran-quantreg 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,224 kB
  • sloc: fortran: 6,741; ansic: 288; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download
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
39
40
41
42
43
44
#### Demo for an rgl Animation of Cobar Ore fitting

require(quantreg)

if(requireNamespace("interp")){
## Make sure the demo does not ``die'' when rgl is not available:
do.rgl <- interactive() && require(rgl)

data(CobarOre)

### Make an initial quite rough fit of the data
fit <- rqss(z ~ qss(cbind(x,y), lambda = .01, ndum = 100),
            data = CobarOre)
dummies <- fit$qss[[1]]$dummies
zcol <- CobarOre$z

if(do.rgl) {
    plot(fit, render = "rgl")
    cat("Now orient the plot as needed:",
	"Resize window,",
	"mouse button 1 to change viewpoint,",
	"mouse button 2 to zoom,",
	"and hit return when ready",sep="\n")
    scan()
    rgl.bg(color="8")
} else {
    if(!interactive()) pdf(file = "cobar-demo.pdf")
    plot(fit)
}

for(i in 1:20) {
    fname <- paste("cobar",i,".png",sep="")
    lam <- 2*i/100
    fit <- rqss(z ~ qss(cbind(x,y), lambda = lam, dummies = dummies),
                data = CobarOre)
    if(do.rgl) {
        rgl.clear()
        plot(fit, render = "rgl", zcol = zcol)
        rgl.snapshot(fname)
    } else {
        plot(fit, zcol = zcol)
    }
}
}