http://ablejec.nib.si/R/MVA08

Page 1

MVA-08 Uporaba R pri seminarju iz Multivariatne analize Podiplomski študij Statistika

A. Blejec andrej.blejec@nib.si

5. junij 2008 Povzetek Prikazane so nekatere možnosti za generiranje veˇcrazsežnih neneavadnih skupin podatkov: podkev, lupina polkrogle, ipd. Metoda temelji na parametriˇcno podani krivulji ali ploskvi priˇcakovanih vrednosti in sluˇcajnih odklonih v veˇcdimenzionalni sferi.

1

Uvod • - vsaka skupina si izbere eno od metod hierarhicnega zdruzebvanja, v literaturi poisce najvec kar je moznega o opisu te metode (natancno kako je dolocena razlicnost med zdruzeno skupino in preostalimi skupinami) in kar je ze znanega o lastnostih metode (npr. ali garantira monotone • razvrstitve) • - vsaka skupina generira vsaj en tip strukture v 3 razseznem prostoru. Tukaj bo slo za vec generairanih podatkov dolocene strukture (npr. bolj ali manj razmazane strukture, bolj ali manj blizu generirane skupine). Vsako generirano strukturo mora skupina graficno predstaviti. • - vsaka skupina preverja, kako dobro izbrana metoda razpozna vsak tip generiranih struktur (vsaj 4 tipe simuliranih struktur podatkov, ki jih bodo naredile vse skupine) • - odgovor na raziskovalno vprasanje: katere tipe generiranih struktur podatkov zna posamezna metoda razkriti.

2

Priprava delovnega okolja

Najprej povežimo potrebne pakete in privzemimo osnovne funkcije za risanje v treh dimenzijah, ki so spravljene v datoteki Graph3d.r. Funkcije so izpisane v dodatku??, njihov opis in uporaba pa v opisu MVA seminarjev za leto 2007 http://ablejec.nib.si/R/mva07.pdf > > > >

options(width = 70) library(Hmisc) library(fields) source("../doc/Graph3d.r")

1


> + + + + > >

3

large <- function(...) { oldpar <- par(mfrow = c(1, 1), mai = c(0, 0, 0, 0), ...) invisible(oldpar) } oldpar = large() par(oldpar)

Krivulje

Krivuljo v prostoru lahko zapišemo v parametriˇcni obliki kot

( x, y = ϕ( x), z = ϑ( x, y)) ali pa

( x(t), y(t), z(t)) > curve.t <- function(x = t, y = x, z = x) { + C <- cbind(x = x, y = y, z = z) + invisible(C) + }

> > > >

large() t <- seq(0, 1, length = 10) curve <- curve.t(sqrt(t), exp(t), t^2) head(cbind(t = t, curve))

[1,] [2,] [3,] [4,] [5,] [6,]

t 0.0000000 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556

x 0.0000000 0.3333333 0.4714045 0.5773503 0.6666667 0.7453560

y 1.000000 1.117519 1.248849 1.395612 1.559623 1.742909

> persp.3d(curve)

2

z 0.00000000 0.01234568 0.04938272 0.11111111 0.19753086 0.30864198


● ●

● ● ● ● ●

●● ●

Z

● ●

● ●

● ● ●

● ●

● ● ●

● ●

Y

● ●

X

4

Sluˇcajni odkloni

Sluˇcajne odklone za neko toˇcko T = ( x, y, z) izberemo kot sluˇcajni odklon v sferi s središˇcem v T. Pri tem vpeljemo lokalne sferiˇcne koordinate za sluˇcajni odmik: x = r cos ϑ cos ϕ y = r cos ϑ sin ϕ z = r sin ϑ Premaknjena toˇcka ima koordinate premaknjene v sluˇcajni smeri, doloˇcene s sluˇcajno trojico (r, ϑ, ϕ), ki so sluˇcajno izbrani iz intervalov: r ∈ (0, ε) ϑ ∈ (−π, π ) ϕ ∈ (0, 2π )

> jitter.3d <- function(X, epsilon = 1, R = c(0, epsilon), + THETA = c(-pi, pi), PHI = c(0, 2 * pi), FR = runif, + FTHETA = runif, FPHI = runif, a = 1, b = 1, c = 1, + deltaPhi = 0.01) { + n <- dim(X)[1] + r <- FR(n, R[1], R[2]) + theta <- FTHETA(n, THETA[1], THETA[2]) + phi <- FPHI(n, PHI[1], PHI[2] - deltaPhi) + x <- a * r * cos(theta) * cos(phi)

3


+ + + + }

> > > > > > >

y <- b * r * cos(theta) * sin(phi) z <- c * r * sin(theta) return(X + cbind(x, y, z))

large() n <- 200 X <- matrix(rep(0, 3 * n), n, 3) newX <- jitter.3d(X, epsilon = 0.2) persp.3d(newX, col = "red", pch = 16) points.3d(X, col = "blue") segments.3d(X, newX, col = "green") ● ● ● ● ● ● ●● ●● ●

Y

Z

● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● ● ● ●●● ●●● ● ● ● ● ● ●● ● ● ●● ● ● ●●● ● ● ● ● ●● ●● ● ● ●● ●●● ● ● ● ● ●● ● ●●●● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ● ● ●● ● ● ●● ●● ●●● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ●● ● ●● ●●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ●● ●● ● ● ●● ●● ●●● ●●● ● ● ● ● ●● ●● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ●● ● ●●●● ● ● ● ● ● ● ● ●●●● ● ● ●● ● ● ● ● ● ● ● ●●● ●● ●● ●●● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●●●● ● ● ●●● ●● ●● ●●●●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●●● ● ● ● ● ● ●● ● ●●●●●●● ● ●● ● ● ●●●●●●●●●●●●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●●●●●●● ●● ● ● ●● ● ● ● ● ●● ● ●●● ● ● ●● ●● ●●● ● ●● ● ● ● ●● ●●● ● ● ● ● ● ● ●● ● ● ●● ● ● ●

X

> pairs(newX, panel = lines, lower.panel = points)

4


−0.10

0.00

0.10

0.1

−0.20

−0.2

−0.1

0.0

x

● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ●●●●● ● ● ●● ● ● ●● ● ●●● ●●●● ●● ● ● ● ●● ● ● ●●● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●●● ●● ●● ● ● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ●

−0.20

y

● ●

● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ● ●●● ● ● ●● ● ● ●●●● ●● ● ● ● ● ● ●●● ● ● ●● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●● ● ● ● ●● ● ● ●● ● ● ● ● ●● ● ●● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ● ● ● ●● ● ● ● ●● ● ● ●● ●● ●●●● ● ●●● ●● ● ● ● ● ● ●● ● ●● ●

−0.2

> > > > > > >

−0.1

0.0

0.1

● ●

0.1

● ● ● ● ●● ● ●● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ●● ●● ● ●●●● ●● ●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●●● ●● ● ● ● ●●● ●● ● ● ● ● ● ● ●● ●●● ● ●● ●● ● ●● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ●● ●●● ● ● ● ● ● ● ●●● ● ●● ● ● ● ●● ●● ●● ● ● ●● ● ●●● ● ● ●●● ● ● ● ●● ● ● ●● ● ● ● ● ● ●

z

0.0

−0.1

0.2

−0.2

−0.10

0.00

0.10

−0.2

−0.1

0.0

0.1

0.2

large() t <- seq(0, 1, 0.01) X <- curve.t(sqrt(t), exp(t), t^2) newX <- jitter.3d(X, epsilon = 0.2) persp.3d(newX, col = "red", pch = 16) points.3d(X, col = "blue") segments.3d(X, newX, col = "green") ● ● ● ● ● ● ●● ●● ●

Y

Z

● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● ● ● ●●● ●●● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ●● ●● ● ● ●● ●●● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ●● ● ● ●● ●● ●●● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ●●●● ● ● ● ● ● ●● ● ●● ●●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ● ●● ● ●●● ●●● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ●●●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ●●●● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ●●● ●● ●● ●●● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●●●● ● ● ●●● ●● ●● ●●●●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●●● ● ● ● ● ● ●● ● ●●●●●●● ● ●● ● ● ●●●●●●●●●●●●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●●●●●●● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ●● ●●● ●● ●●●● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●

X

5


> > > > > > > >

large() t <- seq(0, 2 * pi, 0.01) X <- curve.t(sin(t), cos(t), t) newX <- jitter.3d(X, epsilon = 0.5) persp.3d(newX, col = "red") points.3d(newX, col = "red", pch = 16) points.3d(X, col = "blue") segments.3d(X, newX, col = "green")

Y

Z

●● ● ● ● ●● ●● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ●● ●● ● ●●● ●●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ●● ● ● ● ● ●● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ●●●● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ●● ●● ● ● ●● ●● ●● ● ● ● ● ● ● ●●● ● ● ● ● ●● ●● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ●● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ●●● ●● ● ● ● ●● ● ● ●● ●● ● ● ● ● ● ●● ● ●● ● ●● ●● ●●●● ● ● ●● ● ● ●● ● ● ●● ● ● ● ●●● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ●●● ●● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ●● ●● ●●● ●● ● ● ● ● ●● ● ●● ● ●● ●● ● ● ●●● ●●●● ●● ●●●● ● ●● ●● ● ●●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ●● ● ● ●● ●● ● ●● ● ● ●● ●● ●● ●● ●● ● ●● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●●●● ● ● ● ●● ● ●●●● ● ●●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●●● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ●●●● ● ● ● ●● ● ● ●●● ●● ●● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ●● ●●● ● ●●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ●●● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ●●●●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●● ● ● ● ●● ●● ●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●● ● ● ● ●●●● ●● ● ● ●● ● ●● ● ● ●● ●● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ●●● ● ●●● ● ● ●● ● ● ● ● ● ●●● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●●●● ● ●●● ●●● ●●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ● ●● ●● ●●● ●●● ● ●● ● ● ●● ● ●●●●● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●●● ●● ● ●● ● ● ● ● ●●● ●● ● ●● ● ● ●●● ●● ● ●●● ●●●● ●●● ● ●● ● ● ●●● ● ● ●● ● ● ● ●● ● ● ● ●● ● ●● ● ● ●● ● ●● ●● ●● ●● ●●● ● ●●● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ●●●● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ●● ●●● ● ●● ● ● ● ● ●● ● ●● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ●● ●●● ● ● ●●● ● ●● ● ● ● ●●● ● ● ● ●●● ● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●● ● ●● ●● ● ● ●● ● ● ●●●● ●●●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ●●●● ● ●●● ●● ●● ● ●● ● ●● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●●●● ● ●● ●●● ● ●● ● ●● ● ● ● ● ● ●● ●● ● ● ● ● ●●● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ●●● ●● ●● ●●● ●● ●●● ● ● ● ●●● ●●● ● ● ● ● ●●● ● ● ● ●● ● ●● ●●● ●●● ● ● ● ● ● ●●● ● ● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ●● ●● ● ● ●● ●● ●●● ● ●● ● ● ● ●● ● ● ● ●● ●●● ● ● ● ● ●●●● ●●● ●● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ●● ●● ●● ● ● ● ● ● ●●●● ● ●●●● ● ● ● ● ●● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ●● ● ● ●

X

> > > > > > > >

large() t <- seq(0, 2 * pi, 0.01) X <- curve.t(sin(t), cos(t), sin(2 * t)) newX <- jitter.3d(X, epsilon = 0.25) persp.3d(newX, col = "white") points.3d(newX, col = "red", pch = 16) points.3d(X, col = "blue") segments.3d(X, newX, col = "green")

6


Y

Z

● ●●● ● ● ●● ●●● ● ●● ●● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ●●●● ●●●●● ●● ● ●●●● ● ● ●● ● ● ●●● ● ● ● ● ● ●●●● ●● ● ●● ● ● ●●● ● ●● ● ● ● ●● ● ● ●● ● ● ● ● ●● ●● ●●●● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ●● ●●● ● ● ●● ●● ● ● ● ● ● ●●●● ● ● ● ●●●● ● ● ● ● ●● ● ● ● ● ●●●●● ● ● ● ●● ● ● ● ● ● ●● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●●●● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ●●● ●● ● ●● ●● ● ● ●● ● ●● ● ● ●● ● ● ● ●● ● ●● ●● ●● ●● ● ● ● ● ●● ● ●● ●● ● ●● ● ● ●● ● ● ●●● ● ● ●●● ● ●● ●● ● ●●● ● ● ●● ●● ● ●●● ●● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ●●● ● ●●● ● ● ● ● ●● ● ●●● ● ●● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ●● ●●●● ● ● ● ● ● ● ● ● ●●● ● ● ●● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●●● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●●● ● ● ● ● ●● ●● ● ● ● ● ● ● ●●●● ● ● ● ●● ● ● ● ●● ●●●● ● ● ● ● ● ●●● ● ●● ●●● ● ● ● ●●● ●● ●● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ●● ● ● ●● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ●● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●●● ● ●● ●●● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ●●● ● ●●● ●● ● ●●● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ●● ● ●● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ●● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ●● ●●● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●●● ● ● ● ●● ● ● ●● ● ●● ●● ●●●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ●● ●●● ● ● ●●● ● ●● ● ● ● ● ●● ● ●●● ●● ● ● ● ●● ●● ●● ●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ●● ●● ●● ● ● ●● ● ●● ● ● ●● ●●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●● ● ● ● ●● ●● ● ● ● ●● ●● ● ● ●● ● ●●●● ● ●● ● ● ●● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ●● ● ● ● ●●●●●● ● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●●● ● ● ●● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ●● ●● ● ● ● ●● ●● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ●●● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ●●● ● ● ●●● ●●● ● ● ● ●● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●●● ●● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●●●● ● ● ● ●● ● ● ● ●● ●●● ● ● ●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●● ● ● ● ● ●●● ●● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ●● ●● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ●● ● ● ●● ● ●●●●● ●● ●●● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ●● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●●● ● ●● ● ●● ● ●● ● ● ● ●●● ● ● ●● ● ● ●●● ● ●● ● ● ● ●●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●●● ● ●●● ●● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●●● ● ● ●● ● ●● ● ● ● ●● ● ● ●●● ● ● ●● ● ● ● ●●●●● ●● ● ● ●● ● ● ●● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●●● ●● ● ●● ● ● ●●● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ●● ●● ●● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●●● ● ●● ●● ●● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ●●● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ●● ●● ●● ● ●●● ●● ● ● ●●● ●● ● ● ● ●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●●● ● ● ● ●● ● ●● ●● ●● ● ●● ●●● ● ●● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ●●●● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ●

X

> pairs(newX, panel = "lines", lower.panel = points)

0.0

0.5

1.0

0.5

1.0

−1.0

● ● ●● ● ●● ●● ● ● ● ●●● ● ●●● ●● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ●● ● ●● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●● ●● ● ●● ● ●● ●●● ● ● ●● ● ● ● ● ●● ●● ● ● ●● ●● ● ● ●● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ●●●● ●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ●● ●● ● ●● ●● ● ● ● ● ●● ●● ● ●● ●● ●● ● ●●●● ●●● ● ● ● ●● ● ●● ● ● ●●● ●● ● ●●● ● ●●● ● ● ● ● ● ●● ●● ● ● ●●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ●●● ● ● ●● ● ●● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ●● ●● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ●●●● ● ● ● ● ● ● ● ●● ● ● ●●●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ●●●● ● ●●● ● ● ●● ● ● ●● ● ●●● ● ● ● ● ● ●● ● ● ●● ● ●●● ● ● ● ●●●●● ● ● ● ● ● ● ●●● ● ●●● ● ●● ●●● ● ● ●●●● ● ●● ● ● ● ● ●●● ● ●● ● ●● ●●●●● ● ● ● ● ●● ● ● ●●●● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ●● ●● ● ● ●● ● ● ● ● ●● ● ● ● ●●● ●●●● ●● ● ● ● ● ● ●● ●

−1.0

0.0

0.5

1.0

1.0

● ● ● ●●● ●● ● ●● ● ●● ● ●●● ●● ● ● ● ● ● ● ● ● ●● ● ● ●●●● ● ● ● ● ● ●● ● ● ● ●● ●● ● ●● ● ●● ●● ● ● ● ●●● ● ●●● ● ●● ●● ●●● ● ●● ● ● ● ●● ● ● ●● ● ● ● ●● ● ● ●● ● ●●● ●●●● ● ● ● ● ●●● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●● ●● ● ●● ● ●● ● ●● ● ● ● ● ● ●● ●●●● ●● ● ● ●● ● ● ● ●●● ● ● ● ●● ● ●● ● ●● ● ● ● ● ●● ●●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ●●● ● ● ●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ●● ●● ● ● ● ●● ●● ●●●●● ● ● ● ●● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ●● ●● ● ● ● ●●● ● ● ●● ● ● ●●● ●● ● ●● ● ● ● ●●●● ● ●●● ●●● ●● ● ● ●●● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●● ●● ● ●● ● ● ● ● ● ●● ● ●● ●● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ● ●● ●● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ●●●● ● ● ●● ● ●● ● ●● ● ●●● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ●●● ● ● ●● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●● ● ● ●● ● ● ● ● ● ● ● ● ●●●● ● ●● ●

0.5

y

z

−1.0

7

0.0

● ●● ●●●● ● ● ●● ●● ● ● ●● ● ● ●●● ● ● ● ●● ● ● ● ● ● ●● ● ● ●● ●●● ●● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ● ● ● ● ● ● ●● ●●● ● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ●●● ● ●●● ●●● ●● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ●●● ● ● ● ●● ●● ● ●● ●● ● ● ● ● ● ● ● ●● ● ●● ●● ●● ● ● ● ●● ●● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ●●● ● ●● ● ●● ● ●●●● ●● ●● ● ●● ●●● ●● ●● ● ●●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ●● ● ●●● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ●● ●●● ●● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ●●● ● ●

−1.0

−1.0

0.0

0.5

1.0

−1.0

0.0

x

0.0

0.5

1.0


4.1

Normalno porazdeljen parameter t

Parameter t ima lahko poljubno porazdelitev, ki na nek naˇcin doloˇca gostoto vzdolž krivulje. Parameter primerno skaliramo, v našem primeru najprej med 0 in 1, nato pa ga še primerno raztegnemo, da zavzame normalno porazdeljene vrednosti med 0 in 2π: > > > > + > > + > > +

par(mfrow = c(3, 1)) t <- rnorm(500) xlim <- c(min(t), 2 * pi) hist(t, col = "lightblue", xlim = xlim, breaks = seq(min(t), max(t), length = 10)) t <- (t - min(t))/(max(t) - min(t)) hist(t, col = "lightblue", xlim = xlim, breaks = seq(min(t), max(t), length = 10)) t <- t * 2 * pi hist(t, col = "lightblue", xlim = xlim, breaks = seq(min(t), max(t), length = 10))

40 80 0

Frequency

Histogram of t

−2

0

2

4

6

4

6

4

6

t

40 80 0

Frequency

Histogram of t

−2

0

2 t

40 80 0

Frequency

Histogram of t

−2

0

2 t

Krivulja ima zgošˇcino toˇck na sredini loka: > > > > > >

large() X <- curve.t(sin(t), cos(t), t) newX <- jitter.3d(X, epsilon = 0.2) persp.3d(newX, col = "red", pch = 16) points.3d(X, col = "blue") segments.3d(X, newX, col = "green")

8


Y

Z

● ● ● ●● ●● ● ● ● ●● ● ● ● ●● ● ● ● ●● ●● ● ● ●● ● ●● ●● ●●● ● ● ●●●● ●● ●● ●●● ● ●● ●●● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ●● ●●● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ●● ● ●● ● ● ●● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ●● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ●● ● ● ● ●●● ● ● ● ●● ●● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ●●●● ●● ● ● ●● ●●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●● ●● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●●● ● ● ●● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ●●● ● ●●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ●●●●● ● ●● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ● ●●● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ●●● ●●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ●● ●●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ●● ●● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ● ●● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●●●● ● ● ● ● ●●● ● ● ● ● ● ● ●● ●● ● ● ●● ●● ● ● ●● ● ● ●● ●●● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ●●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●● ●● ● ● ● ●● ● ● ●● ● ● ● ● ● ●● ● ● ●● ●● ● ● ●●● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ● ● ●● ●● ● ● ● ●●● ● ● ●●● ● ● ● ●● ● ● ●● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ●● ● ●● ● ●● ● ●● ● ●● ● ● ●●● ● ● ●● ● ● ●● ● ●●● ● ●● ● ● ● ● ●● ● ● ● ●● ● ●● ● ●● ● ● ●● ●● ●● ● ● ● ● ● ● ●● ●● ● ●●● ●●● ● ●●● ● ● ●● ●● ●● ● ●●●● ● ●●●●● ● ●● ●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●●

X

5

Krogla z enakomerno porazdeljeno oddaljenostjo od središˇca > > > >

6

n <- 300 X <- matrix(rep(0, 3 * n), n, 3) krogla <- jitter.3d(X, epsilon = 0.2) plot.3d(krogla)

Ploskve

Ploskev lahko podamo parametriˇcno

( x, y, z = ϕ( x, y)) toˇcke na ploskvi pa premaknemo v sluˇcajni sferi.

6.1

Parametriˇcna ploskev

Izberemo dvodimenzionalne pare ( x, y) in pri njih izraˇcunamo ploskev: > surface <- function(x = rnorm(n), y = rnorm(n), z = x + + y) { + return(cbind(x = x, y = y, z = z)) + }

9


> > > > > > > > > > >

n <- 25 t <- seq(-3, 3, length = n) x <- expand.grid(t, t)[, 1] y <- expand.grid(t, t)[, 2] X <- surface(x, y, z = x + y) newX <- jitter.3d(X, epsilon = 2) large() persp.3d(X, col = "blue", phi = 0) points.3d(newX, col = "red", pch = 16) segments.3d(X, newX, col = "green") points.3d(X, col = "blue")

●● ● ● ● ● ● ● ●● ●●●●● ● ● ● ●● ● ● ●● ●●●● ● ● ●●● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ●●●● ● ● ●●● ● ● ● ● ● ●● ●● ●● ●● ●● ●● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●●● ●●● ● ● ●● ●●●● ●●● ● ●● ● ● ●●● ● ● ●●● ●●●● ●●● ●● ● ●● ● ● ●●● ●● ●● ● ● ● ● ●●● ●● ●●●●●● ●● ● ● ●●● ●● ● ● ●● ● ●● ● ● ●● ● ● ●●● ●● ● ●● ●● ●● ● ● ● ● ● ●● ●● ● ● ● ● ●● ●● ● ●● ● ● ●● ●● ●● ● ● ●● ●● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ●●●●●●● ●●● ●● ● ●● ● ● ● ●●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●●●●●●● ●● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●● ● ● ●● ●●●●●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●● ● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ● ● ●●● ●● ●● ●●●●●● ●● ●● ● ● ● ●● ● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ●● ●●● ●●●● ● ● ●● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ●● ● ● ●●● ●● ● ●●● ●●● ● ● ●●● ● ● ●● ●● ● ● ●● ● ●● ● ●●● ●● ● ●●● ●● ●● ●●● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ●● ●● ●● ● ● ● ● ● ●● ●● ● ●● ● ● ● ●● ● ● ● ●● ● ●● ● ●●● ● ● ● ●●●● ●●● ●● ● ● ●● ● ●● ● ● ●● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●●●● ● ● ●● ●● ●● ●●●● ● ● ●● ● ● ● ● ● ● ● ●● ● ●● ●●●●● ● ● ●● ● ●● ● ● ● ●●● ●● ● ● ● ● ●● ●●● ●● ● ● ● ● ● ● ● ● ●●● ●●●● ●● ● ● ● ●● ● ●● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ●● ● ●●● ●●● ● ● ● ●●● ●● ● ● ● ●●● ● ● ● ●● ● ● ●● ● ● ● ● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●●●● ●●● ● ●● ●● ● ●●● ●● ● ●●●● ●● ● ● ● ●● ●● ●●● ● ● ● ● ● ● ● ●● ● ● ● ●● ●● ● ● ● ● ● ● ● ●●● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ●●●● ● ●●●● ●● ● ● ● ●● ●● ●●● ●● ● ●●●●● ●● ● ●● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ●●●●●● ●●● ● ● ●● ●●● ● ●●●● ●● ● ● ●● ●●●●●●●●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ●●● ●●● ● ●● ● ● ●● ● ●● ●●●●● ● ● ● ● ● ● ● ● ●●●●● ●● ● ●●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●● ●● ●●●●● ● ● ● ● ●●● ●●●●● ● ●● ●● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ●●● ● ● ● ● ●●● ● ● ●● ● ●● ●●● ● ●●●● ● ●● ● ● ● ●● ● ● ● ● ●●● ● ●● ● ● ●● ●● ●● ● ● ●●● ●● ●● ●●● ● ● ●● ●●● ● ● ●●● ● ●●● ● ●●● ● ●● ● ● ●● ●● ●●● ● ●●● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ●●● ● ●● ●● ● ●● ● ●● ● ● ● ●●● ● ● ● ●●● ● ● ● ●● ● ● ● ●●● ●● ●● ● ●● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●● ●●●● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ●● ●● ●● ●● ● ● ●● ● ● ● ● ● ●●● ● ● ●●● ● ●● ●●●●●● ● ●● ● ●●● ● ●● ●● ●●●●● ● ● ● ● ● ●●● ● ● ●● ●● ● ●● ● ● ● ● ●● ● ●● ●● ● ●● ● ● ● ● ●●●● ● ●●● ● ●● ● ● ● ● ● ●● ●● ●● ● ●●● ● ●● ● ●●●●● ●●● ●● ● ●●● ●● ● ● ●● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ●● ● ●● ● ●● ●●● ●● ●● ●● ●● ● ●● ●●● ●● ● ●●● ●●● ● ● ● ● ●● ● ●●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ●●●● ● ● ● ● ● ● ●● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●●● ● ● ●● ●●●● ●●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ●●● ● ● ●● ●●● ●●● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ●●● ● ● ● ●●● ●●●● ● ●●●● ●● ● ●● ● ● ● ● ●● ● ● ●●● ●●● ●● ● ●● ● ●● ● ● ● ●● ●● ● ● ● ● ●● ●● ● ● ● ● ●●● ●●● ● ● ● ●● ● ● ●● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●●● ● ● ●●●● ●● ● ● ●●● ● ● ●●● ● ●● ● ● ● ●●●●●●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●●●● ●● ● ● ●● ● ●●●● ● ● ●● ● ● ● ●●●●●●●●●●●●● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●●● ●●● ●●●● ● ● ● ● ● ●● ●● ●●●●● ● ● ●●●●●●● ●● ●●● ●● ●● ●●●●●●●●● ● ● ● ●● ● ●●●●● ● ●●● ● ●●●●●● ●● ●●● ●● ● ● ● ● ● ●●● ● ●●●● ● ● ●● ●●● ● ● ● ●● ● ● ●● ● ● ● ●● ● ●● ●● ● ● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ●● ● ●●●●●● ●●●●●● ●● ●● ● ●● ●● ●● ●● ●● ●● ●● ●● ●●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ●●●●●● ● ● ● ● ● ● ● ● ●● ●●●●● ●●●●●●●● ●●●●●● ●●●●●●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ●● ●● ● ●● ●● ●● ●● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●●●● ●●●● ●●●● ●● ●● ●● ●● ●● ●● ●●● ●● ●● ●● ●● ●● ●●● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ●● ●● ●● ●● ● ●● ● ● ●● ● ● ●● ●●●●●●●●● ●● ●● ●● ●●● ●● ●●● ●● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ●● ●● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ●● ● ● ●● ●

Y

Z

X

6.2

Sfera - lupina krogle

> sfera.3d <- function(X = 0, n = dim(X)[1], R = 1, THETA = c(-pi, + pi), PHI = c(0, 2 * pi), FR = runif, FTHETA = runif, + FPHI = runif, a = 1, b = 1, c = 1, deltaPhi = 0.01) { + if (X == 0) + X <- matrix(rep(0, 3 * n), n) + n <- dim(X)[1] + r <- R + theta <- FTHETA(n, THETA[1], THETA[2]) + phi <- FPHI(n, PHI[1], PHI[2] - deltaPhi) + x <- a * r * cos(theta) * cos(phi) + y <- b * r * cos(theta) * sin(phi) + z <- c * r * sin(theta) + return(X + cbind(x, y, z)) + }

10


> > > > > > > > > >

n <- 1000 x <- runif(n, -2, 2) y <- runif(n, -2, 2) X <- surface(x, y, z = x + y^2) newX <- jitter.3d(X, epsilon = 0.5) large() persp.3d(X, col = "blue", phi = 45, scale = FALSE, theta = 60) points.3d(newX, col = "red", pch = 16) segments.3d(X, newX, col = "green") points.3d(X, col = "blue")

Z

● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ●● ●● ● ●● ●● ● ● ● ● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ●● ● ●●●● ●● ● ● ● ● ● ● ●● ● ● ● ●●●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ●●● ●● ● ● ● ● ● ● ●● ● ●●●● ● ●●● ●● ● ● ●● ●● ● ●● ●● ●● ● ● ● ● ●● ●●●● ●● ●●● ● ● ●● ●● ●●●● ● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●●●● ● ● ●● ●●●●●● ● ● ● ●● ●●● ● ● ●● ● ● ●●● ●● ●● ● ● ●●● ● ●●●● ● ● ● ● ●● ● ● ●● ●● ●● ●● ●●●● ● ● ● ●● ●● ● ●● ● ●● ● ● ● ●● ● ● ●● ●● ● ● ● ●● ● ●●● ●●●●● ● ● ●● ●● ● ●● ●●●● ● ●● ● ● ● ● ● ● ● ●● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ●● ● ●● ● ●● ●● ● ● ● ●●● ●●●●●● ● ● ● ●● ● ● ●● ●●●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ●●●●●● ●●●● ● ●● ● ●● ● ● ●● ●● ● ●● ● ●●● ●● ● ● ● ● ● ●●● ● ● ● ●●●● ●●●● ● ● ● ● ● ●● ●● ●● ● ●● ● ● ● ● ● ●● ● ● ● ●● ●● ● ●● ●●● ●● ● ● ● ●● ● ● ● ● ● ●● ●●●●●●●● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ● ●● ● ● ● ●● ● ●● ● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ●●●● ● ●●● ●● ● ● ● ●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ●● ●● ● ● ● ● ●●● ● ● ● ●● ● ●●●●●● ● ● ● ●● ●● ● ● ●● ● ●● ● ● ●● ●● ● ● ●● ●●● ● ● ● ● ● ● ●●● ● ● ● ● ●●●● ● ● ● ●● ● ● ● ●●● ● ● ● ●● ●● ● ● ●● ● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ●● ● ●●●● ● ● ● ● ● ● ●● ●● ● ● ●● ●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●●● ● ● ● ●● ● ●● ● ● ● ● ●● ●●● ● ● ● ● ●● ● ● ●● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●● ● ●● ● ●● ●●● ● ● ●● ● ● ●●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ●● ● ● ● ● ●●●● ● ● ●● ●●● ● ● ● ● ● ● ●● ● ● ●●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●●● ●●● ● ●● ●● ● ● ●● ●● ● ● ●● ●●●● ●● ● ●●●●● ● ● ● ●● ● ● ●● ● ●● ● ●●●● ● ●●● ● ●●● ● ● ●● ● ● ● ●●● ● ● ● ● ● ●● ● ● ● ● ●● ● ●●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ●● ●● ●●● ●●● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●● ● ●●● ●● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ●●● ● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ●●●●●●●● ●● ● ● ● ●● ● ●● ● ● ● ●●● ● ● ●● ●●● ● ●●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ● ●● ● ● ●● ● ● ● ● ●●●● ● ●● ● ●●● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●●● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●● ● ●● ● ● ● ● ● ● ● ●●● ●●● ● ● ●●● ●● ● ● ● ●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●●● ● ● ● ●●●● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ●● ● ●● ● ●●●●● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ●●● ●● ● ● ● ● ● ● ● ● ●●●● ●● ●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●●● ● ● ●●● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ●● ●●● ●● ●● ●● ●●● ●● ● ● ● ● ● ● ●●● ●● ●● ● ●●● ● ● ● ●● ● ● ● ●● ● ●●●● ●● ● ● ● ● ●●● ● ● ●●● ● ● ●● ● ●● ● ● ●● ●●● ● ● ● ● ●●●● ●● ●●● ● ● ● ● ● ●● ● ● ●●●● ●● ● ● ● ●● ● ● ● ● ●●●●●●●●●● ● ●● ● ●● ● ● ● ●● ●● ● ●● ●● ● ● ●●● ● ●●● ●●● ● ●● ● ● ●● ● ● ● ●● ●● ● ●●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ● ●●● ●●●● ●● ●● ●●● ●● ●● ● ● ● ●●● ● ● ●● ● ●● ●● ● ● ●● ●● ● ●●● ● ● ●● ● ● ●● ●● ●● ●● ●● ●● ● ● ●● ●● ●● ● ●●●● ● ● ● ●●●● ● ●● ● ● ● ●● ●● ● ●●● ● ●● ● ● ● ● ●● ● ●●●● ● ● ● ● ● ● ● ●● ●●● ● ●● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ●●● ●● ● ● ● ● ●●●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●● ●●● ● ● ● ● ●● ●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●●● ● ●● ● ●● ● ● ●● ●●● ● ● ●● ● ● ● ● ● ●● ●● ●● ● ● ● ●● ●● ● ●●● ● ● ●●●●●● ● ●●● ● ● ●● ● ● ● ● ●● ● ●●● ●● ● ●● ● ●● ● ● ●●● ●● ●●● ● ●● ● ●● ●●● ●● ● ●● ● ● ● ● ● ●● ●● ● ●● ●●● ● ● ●●● ●● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ●●●● ● ●● ● ● ● ●● ● ●● ● ●● ●●●●●●● ● ●●● ● ●●●● ●●● ●● ● ● ● ●● ●●● ● ● ● ●●●●●●●●● ● ● ● ●●● ● ●●●● ●●● ●● ● ●●● ● ●●●●● ● ●●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ● ●● ● ● ● ●●● ● ● ● ● ●● ● ● ●● ●● ● ●● ● ● ●● ● ● ●● ● ● ● ● ● ●● ● ●●●● ●●● ● ● ● ● ● ● ● ● ●●●

X

Y

> large() > sfera <- sfera.3d(n = 300, R = 2) > persp.3d(sfera)

> > > > > >

large() n <- 200 X <- matrix(rep(0, 3 * n), n) krogla <- jitter.3d(X, epsilon = 1) persp.3d(sfera, col = "blue", pch = 16) points.3d(krogla, col = "red", pch = 16)

11


Y

Z

●● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ●●● ● ●●● ●● ●● ● ●●● ●● ●●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ●●● ● ● ●● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ●● ●● ● ● ● ●●●●● ● ● ● ● ●● ●● ●● ●● ● ●●● ● ● ● ● ● ●● ● ●● ●● ● ●●● ● ●● ● ● ● ●● ●● ● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●● ● ●● ● ● ● ●● ●● ● ● ● ●● ● ●● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ●●● ● ● ●● ● ● ●● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●● ● ●● ● ●● ● ●● ●● ● ● ● ● ●● ● ●● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ●● ●● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●● ●● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● ●● ● ●● ● ● ●● ●● ●● ●●● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●●● ●●● ● ●● ●● ●● ● ● ● ● ● ●● ●●● ● ● ● ●● ● ●● ● ● ●● ●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●●● ●●● ● ● ● ●● ●● ● ● ●● ●● ● ● ● ● ●●● ● ● ● ●●●● ● ●● ● ●● ●● ●● ● ● ● ● ● ●● ● ●● ● ● ● ●●● ● ●● ●●●●● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● ● ●● ● ●●● ●● ● ● ● ●● ●● ●● ● ●● ●● ●●●●●●● ●● ● ● ●●●● ●● ●● ● ● ● ● ●● ●● ●● ● ● ● ● ●● ● ●● ● ●● ●● ● ● ● ● ●● ● ● ● ● ● ●● ●● ● ● ● ●●● ●● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ●●● ●● ●●● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ●● ● ● ● ● ●●● ● ● ● ● ●● ● ●● ● ● ● ●● ●●● ● ●●●● ● ● ● ● ● ● ● ●● ● ●● ● ● ●●● ● ● ● ● ● ●● ●● ● ●●● ● ● ●●● ● ●●●● ● ●● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ●●● ● ●●●● ● ●● ● ● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ●● ●● ● ●●● ● ● ●● ● ● ● ●●●● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●●● ● ● ●● ● ● ●● ●●● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ●● ● ●

X

> > > + + + + +

6.3

large() range(sfera) for (x in seq(-2, 2, 0.1)) { center <- c(x, 0, 0) krogla1 <- t(center + t(krogla)) persp.3d(sfera, col = "blue", pch = 16) points.3d(krogla1, col = "red", pch = 16) }

Vrtenina

Vrtenine so podane v cilindriˇcnih koordinatah r, ϕ, h x = r cos ϕ y = r sin ϕ z = h pri cˇ emer je r ∈ ( a, b) ϕ ∈ (0, 2π ) h = f (r, ϕ) > surface.rot <- function(R = c(0, 10), PHI = c(0, 2 * + pi), z, n = 10) { + rs <- seq(min(R), max(R), length = n) + phis <- seq(min(PHI), max(PHI), length = n)

12


+ + + + + + + }

> > > > > > >

r <- expand.grid(rs, phis)[, 1] phi <- expand.grid(rs, phis)[, 2] x <- r * cos(phi) y <- r * sin(phi) z <- sqrt(max(R)^2 - r^2) return(cbind(x = x, y = y, z = z))

large() X <- surface.rot(z = 1, n = 50) newX <- jitter.3d(X, epsilon = 1) persp.3d(X, col = "blue", scale = FALSE) points.3d(newX, col = "red", pch = 16) segments.3d(X, newX, col = "green") points.3d(X, col = "blue")

Y

Z

● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ●● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●●● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ●●● ●● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ●●●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ●● ● ●●● ● ● ●● ● ●●● ● ●●● ● ● ● ● ●● ●● ● ● ● ● ●● ● ● ● ● ●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ●●●●●●●●●● ● ● ● ●●● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ● ●● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ●● ●● ● ● ●●● ● ● ● ● ● ●●●●●●●●●● ● ● ● ●●●●●● ●● ● ● ● ● ●● ● ●● ● ● ● ● ● ●● ● ●●● ● ●● ● ● ● ● ●●● ●● ●● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●●●●●● ●● ● ● ● ●● ● ●● ●● ● ● ● ● ● ● ● ●● ●● ● ●● ●● ● ●●● ● ● ● ● ● ●●● ●● ● ● ●● ●●● ●●●●● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●● ● ●●● ● ●●● ●●● ● ● ●● ● ● ●●● ● ● ● ● ● ● ● ●●●● ●● ● ● ● ● ● ● ●● ● ● ● ●● ● ●●●●●●● ●●● ● ●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●●●● ● ●●●●● ●●● ● ●●●● ● ● ●● ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ●●● ●● ● ●● ● ● ●●● ● ● ● ● ●● ●● ●●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ●● ● ● ●●● ●●●● ● ●● ● ● ●● ● ●●●●●●●●●●●● ●●● ●● ● ●● ● ● ● ● ● ● ● ●●●●●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ●●●●●● ● ● ● ● ●●● ●●● ● ●●● ●● ● ●● ●● ● ●● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●●● ● ● ● ●●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●● ●●●● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●● ●● ●●● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ●● ● ● ●● ● ● ● ● ● ●● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ●● ●● ● ●● ●●●● ● ● ●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ●● ● ● ●● ● ●● ●●● ● ● ● ●●● ●● ●● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●● ● ● ● ●● ●●● ● ●● ● ● ● ●● ● ●●● ● ● ●●● ●● ● ●● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ●●●● ● ● ●● ● ● ● ●●● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ●●●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ●●● ●●●●● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●●●●● ● ●● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ●● ● ●●● ● ●● ●●●●●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●●●●●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●●● ● ● ●● ● ●●●●●●●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●●● ● ●●●● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●●● ● ● ●● ● ● ● ● ●●●●●● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ●●●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ●● ●●●●●● ● ●●●●●● ● ● ●●●● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ●●●●● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●●● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ●●●●● ● ●● ● ● ●● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ● ● ● ● ●●●●●●●●●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●●●● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ●● ● ●●●●● ●●● ● ● ● ● ● ● ●●● ● ●●●●●●● ● ●● ●● ● ● ● ●●● ●● ●● ● ● ● ●●● ● ●●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ●●● ● ● ● ●● ●● ● ● ● ●● ● ●● ● ● ●●●●●●●●● ● ●●●●●● ● ●●● ●●●●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●●●●●● ●●● ●● ● ● ●●●● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ●●● ● ● ●●●●● ● ●● ●● ● ● ●●● ● ●●●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ●●●●●●● ●● ● ● ● ●●● ● ● ● ● ● ● ●●●●●●●● ●●●●●● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●●●●●●●●●● ● ●●●● ● ● ● ●●●● ●●●●●●● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●●● ● ● ● ● ● ●●●● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ●● ●●●● ● ● ● ● ●●●●● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●●● ●●●● ●●● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ●●●●●● ●●● ● ●● ●●●● ● ● ●● ●● ● ● ● ● ●●●● ●●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●●●● ●● ● ● ●● ● ●● ●●●● ● ● ● ● ●● ● ● ● ●● ● ●●●●● ● ● ● ● ● ● ● ● ●● ● ●●●● ● ●●● ● ●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ●●● ●●●●● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● ●●● ●●●●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ●● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ●

X

7

Multivariatno normalna porazdelitev

Multivariatno normalno porazdeljene podatke in gostoto multivariatno normalne porazdelitve lahko raˇcunamo s funkcijami v paketu mvtnorm > library(mvtnorm)

7.1

Risanje plastnic

> x <- seq(-4, 4, 0.1) > y <- seq(-4, 4, 0.1)

13


> z <- dmvnorm(expand.grid(x, y)) > z <- matrix(z, length(x)) > filled.contour(x, y, z, color.palette = terrain.colors)

4 0.15

2 0.10 0

0.05 −2

−4

0.00 −4

−2

0

2

4

> sigma <- matrix(c(2, 0.5, 0.5, 1), 2, 2) > sigma [,1] [,2] [1,] 2.0 0.5 [2,] 0.5 1.0 > > > > + + + +

z <- dmvnorm(expand.grid(x, y), sigma = sigma) z <- matrix(z, length(x)) XY <- rmvnorm(100, sigma = sigma) filled.contour(x, y, z, color.palette = terrain.colors, nlevels = 7, plot.axes = { par(col = "red", pch = 16) points(XY) })

14


0.14 ●

0.12 ● ●

● ●

0.10

● ●

● ● ● ● ● ● ●● ● ● ● ● ● ●●●● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●

0.08

●●

0.06

0.04

0.02

0.00

4

> contour(x, y, z) > points(XY[, 1], XY[, 2], col = "red", pch = 16)

2

● ●

● ●

0

−2

0.02

0.04 ●

● ● 0.06 ● ● ● ● 0● .08 ● ● ●● ● 9 ● 0.0 ● ●●● ● ● ● ●● 0.11 ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● 0.1 ● ● ● ● ● ● ● ● ● ● ● ● 0.0 ● 7 ●● ● ● ● 0.05 ● ●● ●● ● ● 0.03 ● ● ● ●

● ●

●●

0.01

−4

−4

8

−2

0

2

4

Risanje ploskve > pmat <- persp(x, y, z, col = "lightblue", shade = 0.2)

15


y

z

x

> large() > for (fi in seq(0, 360, 10)) persp(x, y, z, col = drape.color(z, + zlim = c(0, max(z))), theta = fi)

9 rgl > library(rgl) > > + > >

open3d() bg3d(sphere = FALSE, fogtype = "none", color = c("black", "white"), back = "lines") spheres3d(X, col = "blue", radius = 0.05) spheres3d(newX, col = "red", radius = 0.1)

> > + > >

open3d() bg3d(sphere = FALSE, fogtype = "none", color = c("black", "white"), back = "lines") xyz <- cbind(expand.grid(x, y), as.vector(z) * 100) points3d(xyz, col = "blue", cex = 2, size = 2)

> > > > > + >

n <- 200 X <- matrix(rep(0, 3 * n), n, 3) krogla <- jitter.3d(X, epsilon = 0.2) open3d() bg3d(sphere = FALSE, fogtype = "linear", color = c("black", "white"), back = "lines") spheres3d(krogla, col = "red", pch = 16, radius = 0.01)

16


> > > > > > > + > >

n <- 200 X <- matrix(rep(0, 3 * n), n, 3) krogla <- jitter.3d(X, epsilon = 1) sfera <- sfera.3d(n = 300, R = 3) sfera <- jitter(sfera, epsilon = 0.25) open3d() bg3d(sphere = FALSE, fogtype = "linear", color = c("black", "white"), back = "lines") spheres3d(krogla, col = "red", pch = 16, radius = 0.01) spheres3d(sfera, col = "blue", pch = 16, radius = 0.01)

17


A

Funkcije za risanje v treh dimenzijah

Paketi Paket fields vsebuje zanimivo funkcijo drape.colors > library(fields)

catln > catln <- function(...) { + cat(..., "\n") + }

make.matrix > make.matrix <- function(n = 1, m = n) { + s <- matrix(0, nr = n, nc = m) + s <- edit(s) + s + }

my.apply > my.mapply <- function(X, FUN, ...) { + for (j in 1:dim(X)[2]) X[, j] <- FUN(X[, j], ...) + invisible(X) + }

my.aggregate > my.aggregate <- function(x, by, FUN = "mean", ...) { + if (!is.list(by)) + by <- list(by) + as.matrix(aggregate(x, by, FUN = FUN, ...)[, -1]) + }

my.mvrnorm > my.mvrnorm <- function(n = 1, mu = c(0, 0, 0), Sigma = diag(c(1, + 1, 1)), tol = 1e-06, empirical = TRUE, FUN = rnorm, l = 1, + ...) { + p <- length(mu) + if (!all(dim(Sigma) == c(p, p))) + stop("incompatible arguments") + eS <- eigen(Sigma, sym = TRUE) + ev <- eS$values + if (!all(ev >= -tol * abs(ev[1]))) + stop("Sigma is not positive definite")

18


+ + + + + + + + + + + + + + + + + + + }

X <- matrix(FUN(p * n, ...), n) if (empirical) { X <- scale(X, TRUE, FALSE) X <- X %*% svd(X, nu = 0)$v X <- scale(X, FALSE, TRUE) } X <- eS$vectors %*% diag(sqrt(pmax(ev, 0)), p) %*% t(X) X <- mu + X if (!l == 1) X <- box.cox(X, l = l) nm <- names(mu) if (is.null(nm) && !is.null(dn <- dimnames(Sigma))) nm <- dn[[1]] dimnames(X) <- list(nm, NULL) class(X) = "3d" if (n == 1) drop(X) else t(X)

persp.xyz > persp.xyz <- function(X = matrix(rnorm(30), nc = 3), y = NULL, + z = NULL, theta = 30, phi = 30, ndiv = 10, xlim = NULL, ylim = NULL, + zlim = NULL, xlab = "X", ylab = "Y", zlab = "Z", col = 4, + cex = 1, pch = 1, side = "xyz", ...) { + if (!is.matrix(X)) + X <- matrix(X, ncol = 1) + m <- dim(X)[2] + print(m) + x <- X[, 1] + if (m > 1) { + y <- X[, 2] + if (m > 2) + z <- X[, 3] + else z <- 0 + } + if (is.null(xlim)) + xlim <- range(x) + if (is.null(ylim)) + ylim <- range(y) + if (is.null(zlim)) + zlim <- range(z) + if (diff(zlim) == 0) + zlim <- c(-1, 1) + VT <- persp(c(min(x, na.rm = T), max(x, na.rm = T)), c(min(y, + na.rm = T), max(y, na.rm = T)), matrix(rep(c(min(z, na.rm = T), + max(z, na.rm = T)), 2), nc = 2), xlim = xlim, ylim = ylim, + zlim = zlim, theta = theta, phi = phi, col = 0, border = F, + xlab = xlab, ylab = ylab, zlab = zlab, ...) + if (regexpr("x", side) > 0) + points(trans3d(min(xlim), y, z, VT), cex = cex, pch = pch,

19


+ + + + + + + + + + }

col = "gray") if (regexpr("y", side) > 0) points(trans3d(x, max(ylim), z, VT), cex = cex, pch = pch, col = "gray") if (regexpr("z", side) > 0) points(trans3d(x, y, min(zlim), VT), cex = cex, pch = pch, col = "gray") points(trans3d(x, y, z, VT), col = col, cex = cex, pch = pch) invisible(VT)

persp.3d > persp.3d <- function(X = matrix(rnorm(30), nc = 3), y = NULL, + z = NULL, theta = 30, phi = 30, ndiv = 10, xlim = NULL, ylim = NULL, + zlim = NULL, xlab = "X", ylab = "Y", zlab = "Z", col = 4, + cex = 1, pch = 1, side = "xyz", ...) { + if (!is.matrix(X)) + X <- matrix(X, ncol = 1) + m <- dim(X)[2] + x <- X[, 1] + if (m > 1) { + y <- X[, 2] + if (m > 2) + z <- X[, 3] + else z <- 0 + } + if (is.null(xlim)) + xlim <- range(x) + if (is.null(ylim)) + ylim <- range(y) + if (is.null(zlim)) + zlim <- range(z) + if (diff(zlim) == 0) + zlim <- c(-1, 1) + VT <- persp(c(min(x, na.rm = T), max(x, na.rm = T)), c(min(y, + na.rm = T), max(y, na.rm = T)), matrix(rep(c(min(z, na.rm = T), + max(z, na.rm = T)), 2), nc = 2), xlim = xlim, ylim = ylim, + zlim = zlim, theta = theta, phi = phi, col = 0, border = F, + xlab = xlab, ylab = ylab, zlab = zlab, ...) + if (regexpr("x", side) > 0) + points(trans3d(min(xlim), y, z, VT), cex = cex, pch = pch, + col = "gray") + if (regexpr("y", side) > 0) + points(trans3d(x, max(ylim), z, VT), cex = cex, pch = pch, + col = "gray") + if (regexpr("z", side) > 0) + points(trans3d(x, y, min(zlim), VT), cex = cex, pch = pch, + col = "gray") + points(trans3d(x, y, z, VT), col = col, cex = cex, pch = pch) + .pmat <<- list(pmat = VT, xlim = xlim, ylim = ylim, zlim = zlim, + xlab = xlab, ylab = ylab, zlab = zlab)

20


+ + }

invisible(VT)

plot.3d > plot.3d <- persp.3d

trans3d > trans3d <- function(x, y = NULL, z = NULL, pmat) { + if (dim(as.matrix(x))[2] > 1) { + tr <- cbind(x, 1) %*% pmat + } + else if (length(x) + length(y) + length(z) == 3) + tr <- c(x, y, z, 1) %*% pmat + else tr <- cbind(x, y, z, 1) %*% pmat + list(x = tr[, 1]/tr[, 4], y = tr[, 2]/tr[, 4]) + }

points.3d > points.3d <- function(x, y = NULL, z = NULL, pmat = NULL, ...) { + if (is.null(pmat)) + pmat = .pmat$pmat + points(trans3d(x, y, z, pmat), ...) + }

lines.3d > lines.3d <- function(x, y = NULL, z = NULL, pmat = NULL, ...) { + if (is.null(pmat)) + pmat = .pmat$pmat + lines(trans3d(x, y, z, pmat), ...) + }

segments.3d > segments.3d <- function(X1, X2, pmat = NULL, ...) { + if (is.null(pmat)) + pmat = .pmat$pmat + X1 = trans3d(X1, pmat = pmat) + X2 = trans3d(X2, pmat = pmat) + segments(X1$x, X1$y, X2$x, X2$y, ...) + }

21


arrows.3d > arrows.3d <- function(X1, X2, pmat = NULL, ...) { + if (is.null(pmat)) + pmat = .pmat$pmat + X1 = trans3d(X1, pmat = pmat) + X2 = trans3d(X2, pmat = pmat) + arrows(X1$x, X1$y, X2$x, X2$y, ...) + }

eigen.3d > eigen.3d <- function(X, ind = 1:3, scl = 1, plt = T, ...) { + cm = colMeans(X) + e = eigen(cov(X)) + el = t(cm - scl * t(sqrt(e$values[ind]) * t(e$vectors[, ind]))) + eu = t(cm + scl * t(sqrt(e$values[ind]) * t(e$vectors[, ind]))) + if (plt) + segments.3d(el, eu, ...) + list(low = el, up = eu) + }

project.3d > project.3d <- function(X, along = "x", kaj = NULL) { + if (is.matrix(X)) { + x <- X[, 1] + y <- X[, 2] + z <- X[, 3] + } + else { + x <- X[1] + y <- X[2] + z <- X[3] + } + if (regexpr("x", along) > 0) { + if (is.null(kaj)) + lvl <- min(.pmat$xlim) + X <- cbind(x = lvl, y, z) + } + if (regexpr("y", along) > 0) { + if (is.null(kaj)) + lvl <- max(.pmat$ylim) + X <- cbind(x, y = lvl, z) + } + if (regexpr("z", along) > 0) { + if (is.null(kaj)) + lvl <- min(.pmat$zlim) + X <- cbind(x, y, z = lvl) + } + invisible(X) + }

22


show.proj > show.proj <- function(mat, matp = mat, col = + coly = "green", colz = "blue", ...) { + persp.3d(mat, col = 0, ...) + segments.3d(matp, project.3d(matp, "y"), + segments.3d(matp, project.3d(matp, "x"), + segments.3d(matp, project.3d(matp, "z"), + points.3d(mat, col = col) + }

1, lwd = 1, colx = "red",

col = coly, lwd = lwd) col = colx, lwd = lwd) col = colz, lwd = lwd)

show.eigen > show.eigen <- function(mat = X, ...) { + persp.3d(mat, scale = F, ...) + eigen.3d(mat, col = "red", lwd = 4, scl = 2) + }

show.hsv > show.hsv <- function(dx = 0.1) { + mreza = as.matrix(expand.grid(seq(0, 1 - dx, dx), seq(0, + 1 - dx, dx), seq(0, 1 - dx, dx))) + persp.3d(mreza, xlab = "h", ylab = "s", zlab = "v", col = hsv(mreza[, + 1], mreza[, 2], mreza[, 3]), pch = 16, cex = 3, theta = 175) + }

show.rgb > show.rgb <- function(dx = 25, ...) { + mreza = as.matrix(expand.grid(seq(0, 255, dx), seq(0, 255, + dx), seq(0, 255, dx))) + persp.3d(mreza, xlab = "R", ylab = "G", zlab = "B", col = rgb(mreza[, + 1], mreza[, 2], mreza[, 3], max = 255), pch = 16, cex = 3, + ...) + }

B

Manjkajoˇci podatki

defineMissing > declareMissing <- function(x, p) { + if (p == 0) + return(0) + n <- length(x) + if (p >= 1) + p <- p/n + ids <- integer(0) + while (length(ids) < n * p) {

23


+ + + + + > > >

ids <- unique(c(ids, which(runif(n) < p))) } length(ids) <- min(n * p, length(ids)) return(sort(ids)) } length(declareMissing(1:20, 1/2)) length(declareMissing(1:20, 5)) for (i in 1:10) cat(length(declareMissing(1:20, 0.1)))

declareMissing-matrix > declareMissing.matrix <- function(X, p, ind = 1:length(p)) { + n <- dim(X)[1] + m <- dim(X)[2] + ids <- matrix(numeric(2), 1, 2) + for (j in ind) { + if (p[j] > 0) { + id <- declareMissing(X[, j], p[j]) + ids <- rbind(ids, cbind(id, j)) + } + } + ids <- as.matrix(ids) + dimnames(ids)[[2]] <- c("row", "col") + ids[-(ids[, 1] == 0), ] + }

24


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.