gen.LP: Generate Line and Plane Example

Description Usage Arguments Value Examples

View source: R/gen.LP.R

Description

This function generates a toy example of 'line and plane' data in R^3 that data are generated from a mixture of lines (one-dimensional) planes (two-dimensional). When K=2, it gives one line and one plane. For K>2, it gives one line, one plane, and K-2 componenets are randomly chosen to be either a line or a plane.

Usage

1
gen.LP(n = 100, K = 2, iso.var = 0.1)

Arguments

n

the number of data points for each line and plane.

K

the number of mixture components.

iso.var

degree of isotropic variance.

Value

a named list containing:

data

an (2n\times 3) data matrix.

class

length-2n vector for class label.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## test for visualization
set.seed(10)
tester = gen.LP(n=100, K=2, iso.var=0.1)
data   = tester$data
label  = tester$class

## do PCA for data reduction
proj = base::eigen(stats::cov(data))$vectors[,1:2]
dat2 = data%*%proj

## visualize
opar <- par(mfrow=c(2,2))
plot(dat2[,1],dat2[,2],pch=19,cex=0.5,col=label,main="PCA")
plot(data[,1],data[,2],pch=19,cex=0.5,col=label,main="Axis 1 vs 2")
plot(data[,1],data[,3],pch=19,cex=0.5,col=label,main="Axis 1 vs 3")
plot(data[,2],data[,3],pch=19,cex=0.5,col=label,main="Axis 2 vs 3")
par(opar)

## Not run: 
## visualize in 3d
x11()
scatterplot3d::scatterplot3d(x=data, pch=19, cex.symbols=0.5, color=label)

## End(Not run)

kyoustat/mosub documentation built on Feb. 25, 2020, 3:52 a.m.