
R : Copyright 2002, The R Development Core Team
Version 1.5.1  (2002-06-17)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type `license()' or `licence()' for distribution details.

R is a collaborative project with many contributors.
Type `contributors()' for more information.

Type `demo()' for some demos, `help()' for on-line help, or
`help.start()' for a HTML browser interface to help.
Type `q()' to quit R.

> invisible(options(echo = TRUE))
> library(MASS)
> 
> ntw.lrn <- read.table("../lrn/ntw_lrn.dat",header=T,sep=",")
> 
> ntw.names <- names(ntw.lrn)
> 
> y <- ntw.lrn$connection.type
> 
> f23 <- ntw.lrn$count
> f29 <- ntw.lrn$same.srv.rate
> f <- cbind(f23,f29)
> 
> m.neptune <- cbind(mean(f23[y=="neptune"]),mean(f29[y=="neptune"]))
> m.normal <- cbind(mean(f23[y=="normal"]),mean(f29[y=="normal"]))
> m.smurf <- cbind(mean(f23[y=="smurf"]),mean(f29[y=="smurf"]))
> 
> fit <- lda(cbind(f23,f29),y) 
> print(fit$prior) 
  neptune    normal     smurf 
0.2246379 0.2018054 0.5735567 
> 
> size <- 100
> 
> f23.axis <- seq(from=min(f23),to=max(f23),length=100)
> f29.axis <- seq(from=min(f29),to=max(f29),length=100)
> 
> grid <- mat.or.vec(size*size,2)
> for (i in 1:size) {
+   for (j in 1:size) {
+     grid[size*(j-1)+i,1] <- f23.axis[i];
+     grid[size*(j-1)+i,2] <- f29.axis[j];  
+   }
+ }
> 
> pred <- predict(fit,grid)
> 
> yhat <- pred$class
> 
> edge <- mat.or.vec(size*size,1)
> edge <- as.logical(edge)
> for (i in 1:size) { 
+   for (j in 1:size) {
+     cntr <- size*(j-1)+i
+     left <- cntr - size
+     down <- cntr - 1
+     if ( (left > 0) && (down > 0) ) {
+       edge[cntr] <- (yhat[left] != yhat[cntr]) || (yhat[down] != yhat[cntr])
+     }
+     if (i == 1) edge[cntr] <- FALSE
+   }
+ }
> 
> source("psopts.r")
> postscript(file="ntw_lda_rule.eps")
> par.default <- par(no.readonly=TRUE) 
> plot(grid,type='n',xlab=ntw.names[23],ylab=ntw.names[29])
>   points(grid[yhat=="neptune",],pch='.',col="red")
>   points(grid[yhat=="normal",],pch='.',col="green")
>   points(grid[yhat=="smurf",],pch='.',col="blue")
>   points(m.neptune,pch="o",col="red")
>   points(m.normal,pch="o",col="green")
>   points(m.smurf,pch="o",col="blue")
>   points(grid[edge,],pch='+',col="black",cex=0.4)
> dev.off()
null device 
          1 
> 
> ps.options(width=7.0,height=3.0);
> postscript(file="ntw_lda_data.eps")
> par(mfrow=c(1,3),mar=c(5.5,4,3,2)+0.1) # mar=c(bottom,left,top,right)
> plot(f,type='n',xlab=ntw.names[23],ylab=ntw.names[29])
>   points(f[y=="neptune",],pch='o',col="red")
> plot(f,type='n',xlab=ntw.names[23],ylab=ntw.names[29])
>   points(f[y=="normal",],pch='o',col="green")
> plot(f,type='n',xlab=ntw.names[23],ylab=ntw.names[29])
>   points(f[y=="smurf",],pch='o',col="blue")
> dev.off()
null device 
          1 
> proc.time()
[1] 58.93  1.11 60.18  0.00  0.00
> 
