CNwt
QwBU=@a
Qmi
C
O}yW
=
=Q u H
xm
jQ@ w ?
= x@
u s v
CavY
x=oWv=O
|Q t C U t u @ R @ } W =
=@
=L
=
=
| =v
R 122
CU=Q} w
|vWwOv|wUwt O}aUO}U
[email protected] 1390 Q @ =y
? =] C Qy r
t
U
R |U} wvxt=vQ@ u=@ R =@ |}=vW pw= pYi
1 1 1 3 3 4 5 7 7 7 9 9 10 10 11 11 11
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
.. .. .. .. .. .. .. .. .. .. .. .. .. .= .. ..
. . . . . . . . . . . .
. . . . . . . .
i
. . . . . . . . . . . . . . . . . . . . . . . x Ok . . . . . . . . . . . . . . . . |U w x = Q = Q . . . . . . . . . . . . . . . . . . R Q ?Y Q
t
1 1
} v t v @ u @R = J
21
t
Q= i=s v
x_i=L
=}
...... ...... ...... ...... read.table . . . scan ....... .......
=yxO=O
yxO=O R=
Q
P
QO < W= uO m h L w
. . . .
. . . .
.. R = = ......R R = = . . p= =
=H}=
131
QoW}=Q} w
231
=yxO=O
331
=
431
'O
u @R | y
QO
u @ R QO xO t | yxO=O } i R=
O w
O w
wDUO
1531
O w
wDUO
2531
u v= N Q
. . . p= = ........ = } i |wQ
yxO=O
uDWwv
631
O}rwD
731
yxO=O
| y r vO O
= x =@
=H}=
1731
|iO=YD
| y r vO O
= x =@
=H}=
2731
..................... = .................. = Q
=D =
yxO=O Q N U
yQ=O @
hr=
31
531
yxO=O u v= N
u v= N Q
s_vt
R=
CUQyi
v R ]
141
41
12 14 18 19 20 20 21 22 22 23 24 25 25 26 27 28 29 29 30
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . .
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .Q
. . . . . . . . . . . . . . . . . .
=yQ=OQ@
. . . . . . . . . . . . . . . . .
=
. . . .
|wQ
|=} Q
=@ =Lt
1141
C U
............... . | l =D = O =W .. =}rt T Q= .......... w = W
t
1241
} D t
2241
} Q N U x y
u C
a w
w
O
241
=
341
Q=O? JQ J | yxO=O
=
=
w
1341
Q=O? JQ J | yxO=O X= N
. . . . . . . . . . . .
=yT} QD=t
w
=
=
Q=O? JQ J | yxO=O O
@Q m x W
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
2341
. . . . . . . . factor() ` = . . . |= Q = C w w . . . . . . . . . . = C Qy v tR | U | y
@ D
441
}O H t
541
y
CUQyi O=H}=
. . . .
. . . .
. . . .
. . . .
. . . .
=@
. . . .
. . . .
U
1641
. . . .
. . . .
. . . .
.R = = .. Q . . xkr .. `w u @R
@
151
L
251
@= D
351
: : : u t oQ
= w
2351
= Q}eDt
3351
h} QaD Qorta l} CN=U
4351
t | y
|U} wvxt=vQ@
\ W
1351
w |Q H= u t oQ
..... . . . . |rL
641
i
= w
|Q
=}DN=
. . . . . . . .
=H}=
Q=Owtv
32 32 34 36 37 37 39 40 42
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
............... . . . . . . . . curve() ` = ...... = wt ` w
|Q=O
@ D
112
@= D
212
= CtUk
312
wtv OvJ
412
= s |m}i=Qo xQHvB OvJ O=H}=
512
|Q t |Q=O
s}UQD xLiY uwo =vwo
..
xLiY l}
v
| y
|wQ Q=O
u tR y
...... | . . . u} = K]
=
= s}_vD
} B
U
`@=wD
52 53 55
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
=
p=tDL= w Q=t swU pYi
iO
D O= a= w s= o
?
y
r
=
|Q t
x}=B `@=wD
@= D
113
L= | y } R D
213
O }R | @Q m
@
12
712
R= |=xQ B
................ ........ = Q = =`w . | =Y O | =tD = ` w . . . . Q wDU}
sUQ swO pYi
612
HQ N | y
52 52
wtv `@=wD
51
1213
13
56 58 59 60 62 64 65 65
. . . . . . . .
. . . . . . . .
. . . . . . . .
...... qqplot() ...... ...... ...... ...... ...... ......
. . . . . . = Q =tD | =o ` = qqline() qqnorm() |m} Q ` w . . . . . . . . . . . ecdf() ` = . . . . . . = = =tD | =o ` = ................ | . . . . . . . . . . =tD ` = l ................. . . . . . . txQ l w p t v p
w
L=
r
'
J
i= o
t o p
L=
r
J
@ D
2213
@= D
3213
@ D
4213
@ D
5213
=YD
iO
p
L=
i ] wO w
@ D
|
Q}oxvwtv
= QDt=Q=B
Q
OQw @
413
|Q t | yVwQ
513
} | y
} u tR
313
=
=
1513
uw}UQoQ |=ypOt sQ=yJ pYi
68 68 68 69 74 75
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . . . . . . . . |] w} ...... wQ =C w w ......... = O `w . O X}NW . =v}t xr = N u
p t i | y
}O H t
|R Up t
p t
u
]=
@= D
D
1214
Y i
2214
Q
=
O
U oQ | yp t
14
114 214
`H=Qt
77
G
pw= pYi
R |U w x = Q = = | =v } v t v @ u @R @
}
W
11
xtOkt
S-plus x}@ w Auckland =oW
=@ =Lt |=Q@ w |Q=t QwyWt |Q=Ri=sQv xDU@
C U
obert Gentleman
R
= = \U
u } k
D
=}U@ xm OW=@|t |=Qo|W |=} Q |U} wvxt=vQ@ u=@ R l}
WQ
x
=
Q
R
Q=L p=L QO "Ci=} |O=} R u}@]=Nt |OwR@ w OW `wQW "O}OQo ?=NDv= u |=Q@
R Q web xLi http://www.r-project.org %
CU= Q} R KQW x@
xSw B
Y
R
=
v=O Q t xw o QO 1995 p U R=
|v=Wv "O@=}|t xaUwD xv=@r]w=O w Ovm|t
Q CU= xOW |L=Q] |Q=t
xSw B "
= Cra u}ty x@ R
s v
=
\}Lt
QO
CU= TQDUO
"
|U} wvxt=vQ@ u=@ R x@ R=}v =QJ xm O}|t V}B
QO
R}v
w
p= U
spss, sas, Minitab, statistica,
Ov}mv Q=m x=}U x@aH l} =@ \ki
w
O}vm
lQO
|DUQO x@
|Q t
=
wtv
=Q |Q t
1
w
"O W
=
"O
"
u}=
u=
s}DQwor=
=Q
w
xov |rrtr=u}@ s}D l} =Q u=@ R u}=
xDN=OQB
hrDNt
wva
oss Ihaka
|Q=O
|U} wvxt=vQ@
|Q t
R
Q} R O
QDW}@
|
=
R
21
u=@ R =QJ
=} R
C } H
x@ xm u}=
p@k
R=
Q xm u}= ut 'OQ=O OwHw
| yQ= i=s v
w
w |t
OQ= t u= D
w p t 'VwQ
l}
w
p= U
=
T U=
u}= x@ MU=B
xm u}=
Q
|= @
Q
|= @
1390 '
|vWwOv|wUwt
2
O}W=@ xDW=O
"
package, extension
=Q
R
Q =}
|Q= i=s v
w
|
QDW}@ pQDvm OwN |HwQN
xt=vQ@ u=DOwN sD} Qwor= =} "
O}vmv xOvU@
=
w |Q t
=
O}OH
l}Uqm
|Q t
4 V=Dv}mt
Q
= H=
w
3 Tmwv}r '2 Tm}vw} '1 RwOv} w
= sDU}U
| y
|wQ w
OW=@|t R=@
=
Q O}y=wN@ Qo =
| yVwQ |= @
=
| yVwQ
"
O}y=wN@ Qo =
|wQ
x@ \ki
w
O}yO \U@
CU= Q} R KQW x@ u=@ R u}= uU=Lt = O
R
CU= u=o}=Q
u | y m w
=
u @R
w |t
"O W
CU= |@ wN |rN=O
"
=
u @R
=
CU=
"
=
package
| y
w
CU= |v=w=Qi
=
|Q t
S-plus
=HD u* =@ R =@ |}=vW xrRvt x@ u=@ R u}= =@ |}=vW
xDN=UV}B `@=wD
CU= |o}i=Qo x_Lqt p@=k
=tvy=Q
|=Q=O
= C}r@=k
|=Q=O
|
| y
=
CU=
|=Q=O w
=
Q}oO=} "CU=
xO U u |
CN=U
"
"
version 2.6.2 (2008-02-08)
version 2.7.0 (2008-04-22)
version 2.7.1 (2008-06-23)
version 2.7.2 (2008-08-25)
version 2.8.0 (2008-10-20)
version 2.8.1 (2008-12-22)
version 2.9.0 (2009-04-17)
version 2.9.1 (2009-06-26)
version 2.9.2 (2009-08-24)
version 2.10.0 (2009-10-26)
version 2.10.1 (2009-12-14)
version 2.11.0 (2010-04-22)
version 2.11.1 (2010-05-31) 2. Unix
=iDU=
u R=
O}vm xHwD Q} R KQW x@ p=Ft
1. Windows
xO
=Q
3. Linux
4. Macintosh
Q@ Q=m Q_v
w `@=wD
w |v=@ R '
| k
w |t xi==
wtv
R
* * |Q t |Q
"O W
"O
R
u @R
"
u
x@
R
=
u @R
=
=}U@
|O } R Q
w |t |oO=U x@ u=@ R u}=
QO
=@
wva x@ 'CU= x_Lqt p@=k u=@ R u}= <=kDQ= |v=w=Qi
R \}L
OQ t
t QO w
u=
u= D
CN=U
package
w |t
u= D
R
=
u @R
R |U w x = Q
3
=
=@ |}=vW
} v t v @ u @R
version 2.12.0 (2010-10-15) R
CU= Q} R KQW x@
%
OQ=O
|@ wN
S-plus
= =mt=
C v
w u}=
OQ t
"
CNwt
"
O |tv QO
" }
( .exe) | Q
=Q u
p}=i CQwY x@ w OwW|tv xtHQD '=QH=
}= H=
Ovm|tv |v=@}DWB
u}t=Qi O}=@
Gui
CU}v
QO
'u
w |t ?Yv
"O W
=
u R=
R
u |wQ
Q
h L |wQ
TB w
Qo =
w
OQ=O O Hw
|r=wDt l}rm Q=@ wO =@ Q}o|t Q=Qk
"O
R
Q
h L
=Hv=
"O=O s
=Q
w
=H}= u=mt=
|=Q=O
=HD sDU}U l}
=@ |U} wvxt=vQ@
=iDU=
=}rta
Q
w xO
Q xm |vat u}O@ 'CU= QUit
|= @
|=Q=O
?Yv
R
W
D
=
31
RQ]
|wQ
m O W
w |t
u= D
p@=kt
u
QO
v
p}=i =OD@= ==
R=
QDmJwm w =yvt
= Ctqa R=
| y
w |t Q=m u}= |=Q@
u= D
w
TB
a u } B R=
t R @ |=
O}vm l}rm
Y '
xm OwW|t x_Lqt
>
x_i=L QO <=}W= uOQm hPL w CUQyi 'O=H}= x@ "Owtv xO=iDU=
u @R
}= H=
t m
|= @
R-2.7.0-win32.exe | Q =t Q w}B = desktop ?Y pt = R Console x w | = xLi
QO "OQ=O s v
OQ t C
= C}OwOLt
} U R= =Q
pmW x@ uwm} l}
Q_v
=
u @R | y
R C=
wtv 5 Owrv=O
w xO
|D=L}wD Q=Okt l} xLiY u}=
O
=Q u |Q
Q=Ri=sQv
Q @ wO
pYi
1
Ctqa
1 3 1
=H}= uO=O C@Uv Qorta =@ Ov=wD|t |W l}
"O W O
O}vm xHwD Q} R p=Ft
"
>
n { 15 <
O}vR@
"
=Q
Enter O}r
m w xO
n 1] 15
wtv A}=D
=Q
nx
m
CU= |i=m O}vm xOy=Wt
=Q
n
Okt O}y=wN@ Qo =
Q=
>
xm CW=O xHwD O}=@ =t=
wtv
"O
xO
=iDU= R}v
O
" W
Oy=wN
=
=
Qorta
xQ W=
R=
|U} wvxt=vQ@
=yT} QD=t
QO 'u
=
=
| yu @ R
Q}=U Ovv=t
xvwtv l} x@ xm '6 OQ=O
w |t
u= D
uO=O
C@Uv
Q `}Uw Q@ Q=m <- Ctqa
| D
n { 15 n 1] 15 >
Q xD@r=
|= @
<
>
P |t
"OQ= o
=iD
Cw
R
nQ @ w
lJwm
Q
hw L
u}@
R
x {1 X { 10 x 1] 1 > >
<
<
>
%R=
CUDQ=@a C}=U |v=Wv
Q}o Q=Qk =tW
"O
http://CRAN.R-project.org O
"OQ= v =Q
C}Y=N u}=
|w
QDUO
T
QOO
xNUv CU= umtt pta u}= u}L
QO | D } H |
=UD Ctqa xm |DQwY
QO 'O
Q}o Q=Qk
=iDU=
xO
w `@=D l} u=twoQ
OQ t
QO
xm CU=
= x@
|QwO }
sRq "5
wva x@ Ov=wD|t xm |vat u}O@
u=
=
u @R
"6
1390 '
|vWwOv|wUwt
4
X 1] 10 >
C@Uv |W l} x@
"O=O
=@ l}
w |t
=Q CQ a
u= D
n { 10+2 n 1] 12 >
<
>
=Hv= R}v |W
=iDU=
"O=O s
(10+2) 5 1] 60 >
w |t
=Q
A}=D Q]U l}
R=
R= xO
O
uw @ u= D
|=} Q
=}rta xm O}vm xHwD
C
Ctqa =@
= xt=O=
=Q Q m
R
=
"
(10+2) +5 1] 60 >
Oa@
= Q]U =}
u @ R '|
| y
CU= Q} R
CQ Y @
Q]U
w
w x xH}Dv
w
'O W
=ov
w
QO x
'O W
A}=D Q]U
QDW}@
Q}N= p=Ft xm O}vm
wO QO
QO
Q_v
OQ t Q
w
wDUO Qo =
Q
O
|t u=Wv
Z i " yO
+
O}vm x_Lqt
"
=Q |
Qo}O p=Ft
(10+2)* + 5/ + 10+1 1] 5 >
O |twRr
wDUO |y=Dwm Cra x@
"OQ= v
C=Q
|
Oa@
= Q]U x@ uDiQ 'Q}N= p=Ft
| y
R u=@ R xO
=iDU= QoW}=Q} w l}
xm CU= ?U=vt w CU= xOvvmxDUN
R=
O w |t s}UkD xDUO
" v W
=D
xO
wtv l}rm
=
OO
Qy
=Q O N
R @ | } H
w
|va}
R
wm}
u
xLiY Q_v
R
R Console
= O
|
w |t uwvm = "CU= xOW xDWwv
QO
xm CU= |i=m =yO)m O}vR@
=Q
Q
Q
Q Q
m w xO
=
RGui wvt
|q @ |
QO
w
O N
Oa@
wtv A}=D
=Q
w O
w
QO "O W
pN=O QoW}=Q} w l}
TBU
R Untitled - R Editor
|= H= |= @ "O m = H=
Enter O}r
xLiY
R=
=@ |}=yp}=i =yQoW}=Q} w
B
= O Qo =
| y ) m
w
Q
R
Q
w O W = H= Q= i=s v
= xm OwW|t
u |q @
wtv xQ}NP TBU w CWwv OvDUy xm =DOvJ
Q} R QwDUO
w
Ctqa xm |}=H
'OQ=O O Hw >
source("le name") =F
wva x@
wtv xi== R}v
"O
=Q
Q}Ut
TQO
O}=@ p}=i s=v Q@
qa x=ov
xw
'O
w@v
=
|Q H
xWwB
QO
p}=i Qo =
source("E:/users/test.r")
download qkDU O = OvDU} Tinn-R x w | = QoW Q ,
'
wvt
} o
w |vqw] xt=vQ@ l}
v
Q CU=
|= @ "
Q
2 3 1
|= H= 'O @
r O wU
w |t O=H}=
"O W
TB Q=m u}=
R=
OQ t | y ) m u= D
p t u=
>
Q ?Yv xrLQt
New script xv R File
"
>
x@ =yQoW}=Q} w
|wQ 'Q= i=s v
w xOR =Q
w
wO
wDUO lDlD
C=Q
|=yQoW}=Q} w
wO QO
@ u= D
t
t
} @ w y
R
Q pN=O xm OvDUy |}=yv =yQoW}=Q} w u}= R= Qw_vt %|HQ=N
v Q= i=s v
}= } w R=
xDUO u}= u}@
OvDUy
R= "
=HD =yv
|Q
=
=o}=Q =yv
R= |=xQ B w u
R=
= QoW}=Q} w
| y
|a@ "OvwW
R |U w x = Q
5
wtv
=@ |}=vW
wN@OwN x=ov 'OR =OY u pN=O =Q
O
wtv =QH=
"O
O
R
xDWwv
=Q x W
R
= O
CU=
|Q
w |t
| y ) m u= D
wtv |]
=Q
w |t s}UkD
w O W
download RWinEdt =Q
CU= u=o}=Q =Pr
"
w
= x@ |=
@ } w
R
O}vm =QH= Q=@m}
"
library ("RWinEdt") w |t O=H}= QDw}Bt=m
"O W
RGui O =
desktop
|wQ
}= } w R= xO
v =Q
OW=@|t
}= } w
RWinEdt QoW Q =iD Q ?Y WinEdt R Q O = OD xDU = package O = xr Q u
'O m
s v
Tinn-R QoW Q {
=Ut CtUk wO@ QDw}Bt=m xLiY
Q} R pL=Qt O}=@
=HD Q=Ri=sQv u}= xm OwW|t u=Wv Q]=N xD@r=
?Yv =Q u TBU w xOwtv
|w
Q= i=s v } @
R
Q
= xDU@
Q
Q} R QwDUO
|Q= i=s v | y |= @ =Q
RWinEdt
pYi
w
Q= i=s v u= D
"O
"
xQ W=
w |t u ?Yv R= TB w CU= u=o}=Q 7
Q
1
XEmacs RWinEdt
=
"O
>
=
} v t v @ u @R
'
R
Q
U= |= @
@=
}= QO
} @ =
L t
{
w xDU@ "O}vm
j i
R
Q
Q= i=s v QO
wva CLD uwm} l} '=QH=
u=
TBU
TB
R=
q@k xm OR=U|t u=Wv Q]=N "Owtv =QH= w CWwv jwi QoW}=Q} w QO u=wD|t =Q Q_v OQwt |=yO)m
} @,
O = O
=
" W @ x W R @
R w u}vJsy "OvwW|t XNWt
xO=O ` v
%
\rDNt 'QDm =Q=m =} `@=D
O
wDLt
|
CU= C}YwYN
mode |r |t = x data
w
'|O a %OQ=O O Hw
w |t p=Ft
R= u= D
Q
|= @ "OwQ
w
=y|W s=tD
Q |t u}at 8 C}YwYN =@
=yJ "Ovm|t XNWt xm
w
OQ t QO
W
"OO o
Y= ` v Q
v Q m @
RO
= \UwD =yu OwN xm Ovm|t Q=m =y|W =@
w s v
wO |=Q=O
QO =yxO=O
w
OQ=O O Hw
R}v
=Q
x_Lqt xm Qw]v=ty Q |W
OQ=O Q= k
|W l} QY=va `wv
Qo}O
|
=
| y
3 3 1
mode xD@
%
mode
|k]vt
r= "
Q
=
QO
xm
w
=@
"O @ s v CQ a
O
|t u=Wv
" yO
=Q
|W l} QY=va "
x {1 mode(x) 1] "numeric" length(x) 1] 1 A { "Auchland" compar { TRUE z { 1i mode(A) mode(compar) mode(z) 1] "character" 1] "logical" 1] "complex" >
OaD
O=
length
%
O}vm xHwD Q} R
=
w
p ]
=F x@ uwvm =
| yp t
<
>
>
>
<
<
<
>
O w |t wQ@ wQ Q} R s=e}B =@ xvQow OwW xDWwv
" } W
Error: object "true" not found
7. This is Not Notepad
8. attribute
R
Q
nQ @ hw L
=@ O}=@ ,=tDL
TRUE
xS=w
xm O}W=@ xDW=O xHwD
1390 '
|vWwOv|wUwt
6
w |t
"O W
10
NaN =
O =@
O
@ =Q u ' W v O a Q=
NA w x O =W -Inf Inf = C w
=Wv 9
xO=O u
Okt Qo = "OyO|t u
CQ Y
v
w
@ x W O
@
wkit
x@
@ v
=
w
| yxO=O OQ t QO
=Q 1
pFt 'u}at=v
O}vm xHwD Q} R
=
"
x { 5/0 x 1] Inf exp(x) 1] Inf exp({x) 1] 0 x{x 1] NaN
mode C}
wYN
Y
O Q}O=kt
|O a
R
=
u @R
=F x@ "OyO|t V}=tv
| yp t
<
>
>
>
>
>
"
O}vm xHwD Q} R
=
x { "This is a test." x 1] "This is a test." x { 'This is a test.' x 1] "This is a test." >
=F x@ "O}yO Q=Qk
| yp t
quotes
wO
=}
w
l} pN=O
xm CU= |i=m xDWQ O=H}=
=Q u
Q
|= @
<
>
>
<
>
xDWQ pN=O w
QO
=iDU=
'O W xO
Qo =
wvm = "CU=
u
quotes l
} R=
quotes
Qo = =t=
w
wO CQ Y
O
w
'OQ= v O Hw
quotes
x@ pY=L 'O}vm pta
|rmWt
quotes
=iDU=
wO R= xO
O}}=tv
"
=}
wO
w
l} =@ xJ xm O}vm xHwD
w
CQ Y QO '
=iDU=
xO
n R=
CW=O OwHw
O}=@
w
x { "Ali's apple" x 1] "Ali's apple" x { 'Ali 's apple' x 1] "Ali's apple" >
hQ
wDU=B
O}|t V}B =]N
<
>
>
<
n
>
O}vm xHwD Q} R p=Ft x@
wtv pQDvm
"
"O
=Wa= s=kQ=
=Q |Q
O=
OaD
w |t
digits
=
OaD
=iDU=
options ` =
u= D
Q
wDUO =@
print(1/1:5, digits=2) 1] 1.00 0.50 0.33 0.25 0.20
>
= u}=
Q m
Q O =@ wDUO Qy
|= @ " W v Q
QO
=yv s}_vD
Q
=} Qo}O xm Owtv u}at |rm Qw]x@
|= @ |R v
=Wa=
=Q Q
w |t
"O W
options(digits = 3) print(1/1:5) 1] 1.000 0.500 0.333 0.250 0.200
sQ kQ= O= xO
w |t xD@r=
u= D
@ D R=
> >
=
A J
|W l}
R=
V}@ xm O}W=@ p}=t xJv=vJ
w
Ovm|t
=
A J =Q "
9. Not Available
10. not a number
|W l} \ki
print() ` =
O}vm xHwD Q} R p=Ft x@
@ D
wtv
"O
xm O}W=@ xDW=O xHwD ,=vt
=iDU=
xO
cat() ` =
@ D R=
O}=@
Q
OO o
R |U w x = Q
7
=
=@ |}=vW
} v t v @ u @R
x { 1:10 cat('x=', x, '\n') x= 1 2 3 4 5 6 7 8 9 10 >
pYi
1
<
>
=
O
A J = H
Q]U
O
wO QO O= a= w
x=
CtUk xm O}y=wN@ Qo =
wNv sy x@ >
=
"OQ
xm CU= u}=
| H
O}vm pta Q} R
"
' n' CtU
Q \
|= @
w
k
x@ O}=@ OvwW
CQ Y
x { 1:10 cat('x=', '\n', x, '\n') x= 1 2 3 4 5 6 7 8 9 10
>
<
>
R u=@ R
QO xO=t |=yxO=O
4 3 1
R = trees Nile LakeHuron iris cars
Ovv=t "OwW|t xO=iDU= u R= R}v Q=DWwv u}= QO xm CU= xOW xO=O Q=Qk =yp=Ft QO xO=iDU= |=Q@ xO=t xO=O |O=OaD
R Q data()
Ci=}
"
>
QO
wDUO
}R Q
R= xO
=iDU= =@ =Q =yu pt=m CUQyi u=wD|t xD@r=
O w Q
Qty
" v= N= i =Q u x=
w |t Q} R QwDUO =@ 'OW
=
wtv x_Lqt Q} R QwDUO \UwD
"O
data(package="gstat") x_ q Q wD = meuse.alt x
'
xO
| yxO=O u= D
library(gstat)
>
::: w
=Q
gstat xDU
@ QO GQ
'
Ovt
'
package l
=iDU=
u @ R QO
=
CUQyi
| yxO=O
'
} R=
Qo = ,=vt
w |t uwvm =
u= D
>
L
t
} R C=Q
UO @ =Q
w Q
=
O CUQyi |=yxO=O |t=U= u=}t R=
@ \ @ t | yxO=O 'x W
w |t p=Ft
u= D
wva x@
u=
wtv
"O
data(meuse.alt) meuse.alt
> >
p}=i R= =yxO=O uOv=wN wtv
"O
xO
=iDU=
w |t Q=m u}=
VwQ wO R= u= D
Q O w |t p}=i
|= @ " v= N
text
|wQ R= =Q
|vDt
5 3 1
=
| yxO=O
read.table uOv=wN QwDUO = x@ |=xWwB
s v
cw
qFt w OW=@
}=QO QO ,
QO w
data.txt |r =
= Qo = "CU=
} i s v
Ovm|t pta Q} R
"
>
w
CQ Y
mydata { read.table("c:/test/data.txt") Q windows p = sDU} x | w C O XNW /
=iDU=
@ D xO
t a
wvm =
p t u
1 5 3 1
w
wDUO u}rw=
OQ t Q
x@ uOv=wN QwDUO x=ov 'OW=@ xOW xQ}NP
Q
=iDU=
"O m xO
U QO
m
nn wO R=
DQ Y QO '
O}=@ O}vm
xO
U= x W
=iDU=
n O
t
=tv
R=
=@ p}=i
TQO
O}y=wN@ xJ=vJ
=}
w
Q |t
"OO o
test
Q}Ut xm O}W=@ xDW=O xHwD =iDU=
xO
mydata { read.table("c: test data.txt") <
nn
nn
=tv
n O
w |t |U} wvR=@ Q}N=
"O W
>
=
u @R
<
|= @
=F
read.table() ` =
R
= u}=
R= Q m
w x
=
CQ Y @ q @
1390 '
|vWwOv|wUwt
w x CU= s=v
Q ] @ "
8
|=Q=O u
Q}eDt Qy xm OwW|t p}mWD
mydata
mydata$V1, mydata$V2, = w x = x read.table wD O = | mydata, 1], mydata, 2],
w
| yCQ Y
Q
UO " W @
@
yu
@
wtv
xO
=iDU=
w
CU= xOW xQ}NP
"
|rwOH l}
w
j i Q
wDUO
Q
|= H=
w |t xO}t=v
w O W
Z i
:::
w ?UL
u R= OQ t
R=
=@
V1, V2, Q V} mydata"V1"], mydata"V2"], =
|UQDUO
t
"O
= x@ =yxO=O
s v
w |t xm CU=
u= D
data.txt Q
w
} R CQ Y
=}DN=
|Q
B }
=} wYN pt=W
C Y
x@ |r}=i "O}vm xHwD Q} R p=Ft x@ uwvm =
Author: John Davis Date: 18-05-2007 Some comments... Col1, Col2, Col3, Col4 23, 45, A, John 34, 41, B, Jimmy 12, 99, B, Patrick
w |t xOv=wN=Qi
"O W
R
=
=
u @ R QO q L
mydata { read.table("c:/test/data.txt",skip=3,sep=",",header=T) mydata w Q sep = w Ov | w@ C =L} w w Q x p = Q] x skip = w read.table() ` = Q = O =t | P = u} TRUE hiN x T =Hv C |k]v w x header = w
>
<
>
p o }w
u t oQ w t
m
m
t Q
a
}= QO w "
U= C
D \ @ t
m
U=
t ` v R=
m
} i pw=
U
U R=
u t oQ
u t oQ x Nq @ w
O}vm xHwD |HwQN x@ uwvm = "Ovm|t ^iL
=Q
}
v
@ D QO
t h L =Q
yxO=O
@
=yxO=O |t=U= u}=Q@=v@ 'xOW Qm P CU=
Col1 Col2 Col3 Col4 1 23 45 A John 2 34 41 B Jimmy 3 12 99 B Patrick =F x@
p t
wtv
"O
P =
|Q= os v =Q
=yu
w |t OW=@v x=wNrO s=v
u= D
|=Q=O
=}
w
OvW=@ s=v Ok=i Q_v
w
=
= Or}i Qo =
OQ t | yxO=O | y
O}vm xHwD Q} R
"
x { 1:3 names(x) NULL names(x) { c("a", "b", "c") x a b c 1 2 3 names(x) 1] "a" "b" "c" names(x) { NULL x >
<
>
>
<
>
>
> >
<
R |U w x = Q
9
=
=@ |}=vW
} v t v @ u @R
1] 1 2 3 w |t s=Hv=
"O W
dimnames()
Q
wDUO \UwD Q=m u}= "OvDUy
P = p@=k
|Q= os v
=Q
=yQ]U
w
pYi
1
=yuwDU '=yT} QD=t
Q
|= @
x { matrix(1:4, 2) rownames(x) { c("a","b") colnames(x) { c("c","d") x c d a 1 3 b 2 4 dimnames(x) 1]] 1] "a" "b"
>
<
>
<
>
<
>
>
2]] 1] "c" "d" "
x { matrix(1:4, 2) dimnames(x) { list(c("a","b"), c("c","d")) c d a 1 3 b 2 4 >
CWwv
w |t R}v Q} R
u= D
w
CQ Y
x@
w
w xD@r=
=
|DL
=Q j i OQ t
<
<
O}vm xHwD OW Oy=wN ?UJQ@
"
wO |=Q=O
xm
w
=F x@
j i p t
"O
wtv x}=Q=
=Q
?UJQ@
R=
K]U
w |t
wO u= D
R
u @ R QO
x { matrix(1:4, 2) dimnames(x) { list(rows = c("a","b"), cols = c("c","d")) cols rows c d a 1 3 b 2 4 >
<
<
scan uOv=wN QwDUO =t}kDUt R}v Q@ Q=m xr}Uw x@ Ov=wD|t `@=D u}= "Ovm|t
,
pmW
w |t
"O W
=iDU=
xO
O
|tv Q_v x@ ?U=vt
u R= ' UQ
scan() read.table
=iDU=
xO
= x@
s v
Q u}}=B K]U `@=D
| D
Qmrta xm
O
=
R=
2 5 3 1
read.table ` =
=
@ D
w
CU= Q} R KQW x@
"
>
u
|twtta
scan(x, le=" ") p}=i |wQ =yxO=O uDWwv OU} wv|t p}=i
"
>
O w Q
C kw= R= |=xQ B QO w O W x v= N= i
write.table(x, le=" ")
|wQ =Q
=yxO=O
6 3 1
write.table
wDUO
Q
1390 '
|vWwOv|wUwt
OvwW|t xQ}NP
u QO
10
le=" "
=yxO=O xm CU= |r}=i s=v
w
QO w O W x
x
Q}NP CU= Q=Qk xm CU= |}=yxO=O
xm
u QO
Q}o|t Q=Qk
"O
=yxO=O O}rwD OvW=@|t Q} R KQW x@ xm 'OvDUy O}rwD p@=k
w
x@ =yxO=O
=yxO=O R= s_vt |=yxr=@vO O=H}=
1 7 3 1
"
O Q}o@ Q_v
" }
>
x { 1:30
QO =Q
7 3 1
30 = 1
=
qFt 'K}LY
O
| yxO=O ,
D
CQ Y wO
s_vt xr=@vO
O= a= R=
<
"OQ=O
C} wrw=
O
:
= Qorta u}@
|O a | y
QO '
Qorta "CU= QYva
30 =
x
l}
@ |= }=Q
w
wDUO xH}Dv
Ov=wD|t
seq() ` =
j i Q
1:10-1 1] 0 1 2 3 4 5 6 7 8 9 1:(10-1) 1] 1 2 3 4 5 6 7 8 9 >
>
=F
wva x@ "Ovm O}rwD
%p t u=
=Q
|k}kL
x =@
O
O= a= R= |= r vO
@ D
seq(1, 5, 0.5) 1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 >
u}vJsy "OyO|t u=Wv
=Q
V}=Ri=
R}t OOa u}twU
u=
w
xr=@vO xtD=N OOa u}twO 'xr=@vO
Q
O u}rw= '`@=D u}=
`w W O a
"
seq(from=1, to=5, length=9) 1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
CWwv
QO
w |t
u= D
>
CU= xOW s}UkD
" "OQw QO
xr=@vO l}
w
CQ Y
x@
=Ut CtUk
|w
Q sy Q=vm
w O=O Q= k
=Q
9 x 5 = 1 u} @
Q_v
c(1, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0) 1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
D
w
@
O
xrY=i =Hv}=
QO
c() ` =
=@
w |t
OQ t O= a= u= D
@ D
>
= w
pw= u t oQ
QY=va Q=QmD O=OaD
= w
u u t oQ
u}twO
Q
= w
w Q=O @ u u t oQ
u}rw= xm
w
OQ=O O Hw
rep()
wva CLD
u=
Qo}O `@=D
|
O}vm xHwD Q} R p=Ft x@ "CU=
"
rep(1:4, 4) 1] 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 >
Qy Cr=L u}=
QO " "
CU=
= w
Q QY=va
pw= u t oQ Q=O @
O=
OaD =@ Q@=Q@
O}vm xHwD Q} R p=Ft x@ uwvm = "Ovm|t u}at
u
QY=va = w
=Q pw= u t oQ
OaD xm OW=@
O=
QY=va Q=QmD
rep(1:4, c(2,2,2,2)) 1] 1 1 2 2 3 3 4 4
Q Ov=wD|t R}v
Q=O @
OaD
O=
= w
swO u t oQ
= w
Q QYva
'swO u t oQ Q=O @
>
O}vm xHwD
"
rep() ` =
@ D R=
Q} R
=
=F x@
xO U p t
R |U w x = Q
11
=
=@ |}=vW
} v t v @ u @R
rep(' ', 3) 1] " " " " " >
pYi
1
"
=yxO=O R= |iO=YD |=yxr=@vO O=H}=
R = Q| Q rfunc(n, p1, p2, ) pt=W
u @ R "OO o
t
:::
O}rwD CU= Q=Qk xm CU=
= u}=
m P xQ @
w
CQ Y
O
|O= a= O=
QYDNt KQW u}=Q@=v@ "CU= O}rwD p@=k
QO |
=
= ` w \UwD xr=@vO `wv u}=
|Q t | y } R D
x@ `@=wD u}= |twta pmW "CU= p=tDL= |r=oJ w sQH `@=wD R=
OaD
n=
CU= xOW PN= |iO=YD |=vat x@
yu QO "
O}vm xHwD Q} R p=Ft x@ "OyO|t u=Wv
"
=Q
`@=D
2 7 3 1
random r = Q =k p1, p2, xS=w R=
= QDt=Q B
| y
x_Lqt p@=k O=OaD
|=
}O
Q
xm CU=
h L
Q
t
w
hw L "O W
rnorm(1) 1] 1.358007 >
CU= xOW O}rwD l} Q=}at
"
QLv=
h=
w
QiY u}ov=}t
O =D
= Q |iO=YD OOa l} =Hv}=
OQ= v U= p t v
=yxO=O
wtv
"O
Oyov Q} R
|Q=
=
w
x@
| yCQ Y
=Q
41
Q=DN=U
=yxO=O
w |t
u= D
(vector)
R
=
u @ R QO
Q
Q=O @
(matrix) T Q =
} D t
(array) x (data frame)
Q=O? JQ J | yxO=O
=
=
Q
=
v tR | U | yxO=O
(list) C
U
w |t xDN=OQB =yu
R=
l} Qy
OvDUy u=Um} `wv =@ =kt x@ "CN=U
p
xO=O
Q
=Q Q=O @
OvJ pt=W xm CU= |D}OwHwt
c() ` =
=
Q OvDUy =yQ=OQ@
Q=O @ "
R
'
w |t OW x_Lqt R}v ,q@k xm Qw]v=ty "OvW=@|t
@ D @ u= D
=
u @ R QO
::: w
Qyi
RHt KQW x@ uwvm =
|=
=yQ=OQ@ '
(time series) | =
"O W
}=Q
w
QO
1 4 1
=yxO=O Q=DN=U u} QDxO=U
|k]vt ,=t=tD =}
O = =tD
w O a ,t
O}vm xHwD Q} R
"
x - c(10,5,3,6) x 1] 10 5 3 6 >
<
>
=}
w
1390 '
|vWwOv|wUwt
12
y { c(x, 0.55, x, x) y 1] 10.00 5.00 3.00 6.00 0.55 10.00 5.00 3.00 6.00 10.00 5.00 3.00 13] 6.00 >
<
>
=yQ=OQ@ |wQ |=} Q C=@U=Lt Ovm|t `@ Qt =Q
"
x
Q QYva Qy
Q=O @
xx
=F
Q
1 1 4 1
w |t s=Hv= VQYva Qy |wQ ,qwtat |OOa |=yQ=OQ@ |wQ C=@U=Lt
p t |= @ "O W
x 1] 10 5 3 6 z {x x z 1] 100 25 9 36 >
>
<
>
wtv p=ta=
"O
x
Q
s}DQ=or `@=D ,qFt
Q=O @ |wQ =Q
"O=O
QF=
Q l} QY=va
Q=O @
|wQ =Q
`@=wD
w |t
u= D
log(x) 1] 2.302585 1.609438 1.098612 1.791759 >
=F
w
p t "O W
QD|vqw]
Q
O x@ =D
Q=O @ xR= v=
Q |t Q=QmD QOkv QDx=Dwm
OO o
Q OvW=@v u=Um} pw]
Q=O @ '
O Q}o Q_v
" }
sqrt(x) + 2 1] 5.162278 4.236068 3.732051 4.449490 w | `t 2 O = Q QYv Q TB Q x
Q
|=Q=O Q=O @ wO
O l}
QO =Q O a
xm |Dr=L Q
QO
=
w Q=O @ xO U
>
"O W
t
H
O a
@ Q=O @
a
y
U w OO o
Q
w
O x@ =D CU= xOW Q=QmD Q=@ Q=yJ
Q=O @ p ] xR= v= "
OvW=@
Q Ovwrta
Q=O @
2
O =Hv}=
O a
QO
Qy xm xm O}vm xHwD |r=Ft x@ uwvm =
wO
x { c(1,2,3,4) y { c(1,2,3,4,5,6) z {x y Warning message: In x y : longer object length is not a multiple of shorter object length z 1] 1 4 9 16 5 12 >
<
>
<
>
<
>
Q=OQ@ Q} R O=H}=
wtv O=H}=
Q Q
"O
=F
O}vm XNWt
p t "
w
=Q Q=O @ } R
l}
=NDv= O}=@ xm
=Q O W ?
w |t
u= D
Q =v
w
CQ Y wO
=tW
=iDU= =@
| Y a xQ
x { c(3,11,8,15,12) x c(2,4)] 1] 11 15 >
<
>
wtv
"O
>
x { c(3,11,8,15,12) <
P
h L =Q sRq
Q}e QY=va
w |t QY=va
u= D
=tW |ivt
xQ
O
O= a= R= xO
x@
R |U w x = Q
13
=
} v t v @ u @R
=@ |}=vW
1
pYi
x -c(2,3)] 1] 3 15 12 >
"
O}vm xHwD
w |t s=Hv=
'O W
x { c(1,3,6,10,15) x 1] 1] 1 x 5] 1] 15 length(x) 1] 5 dim(x) NULL nrow(x) NULL ncol(x) NULL O= Q | wD Q l xx >
u |wQ C
=}rta
wva x@ xm
u=
w x@ "CU=
|OQ= t
Qit Q} R
Zw
w x
CQ Y @
x
Q
Q=O @
<
>
>
>
>
>
>
} @ 'OO o
v
U Q=O @
}
m
O}y=wN@ Qo = "CU}v O=a@=
|=Q=O
T} QD=t
O}vm xHwD Q} R
"
x { as.matrix(x) dim(x) 1] 5 1 =W NA C q = = R >
qN Q@
h
= O x@
| y ) m
"O
Q O}vm|t x_Lqt xm Qw]u=ty
Q=O @ '
wtv h} QaD T} QD=t l}
w x
CQ Y @ =Q u
<
>
u
v
t
xU =Hv}=
QO "O
a @ yu
=
w
u @ R QO CQ Y
wtv xaH=Qt u=@ R
u}= QO "OvW=@ xOW Owkit |}=yxO=O =} xO=O xm CU= umtt =yxO=O |QU QO
=tvy=Q x@ O}=@ xm 'CU=
|
NA
=iDt =y
Cw
w
OQ t QO
R`w
@= D
pta
wLv "OvwW|t
|x
Q |t Qm P p=Ft
"OO o
"
Ovm|t pkDvt
Q
| U
QN x@
=Q
NA
=
| yxO=O
xO=O
wva x@ `@=D
u=
order() ` =
@ D
1
x { c(1, 20, 2, NA, 22) order(x) 1] 1 3 2 5 4 x order(x)] 1] 1 2 20 22 NA >
<
>
>
Ovm|t
"
P
w x w
h L O N @O N =Q
NA
=
| yxO=O
sort() ` =
@ D
2
x - c(1, 20, 2, NA, 22) sort(x) 1] 1 2 20 22 >
<
>
na.rm=T |D x { c(1, 20, 2, NA, 22) mean(x) 1] NA =Hv=QU =Q Q=m
"O=O s
> >
<
w
UO CQ Y
x@ O}=@ w Ovm|tv pta jwi `@=D wO R= l}I}y pFt
mean() ` =
@ D
3
1390 '
|vWwOv|wUwt
14
mean(x, na.rm=T) 1] 11.25 >
wtv
"O
=iDU= R}v Q} R pL
xO
w |t xD@r=
x=Q R= u= D
x { c(1,2,NA,3,4) y { x !is.na(x)] mean(y) 1] 2.5 >
<
>
<
>
cumsum() `@=D i `t
H
Q@=Q@
u
QYva u}t=
i
w
CU=
=
|OwQw | yxO=O
x}rw=
Q Q@=Q@
Q=O @
"
w xm Ovm|t O=H}=
u p ]
O}vm xHwD Q} R p=Ft x@ "CU=
Q
=Q |Q=O @
cumsum() ` =
@ D
=
|OwQw | yxO=O pw=
QYva
cumsum(rep(2,10)) 1] 2 4 6 8 10 12 14 16 18 20 >
=yT} QD=t uDN=U
Q CU= u=Um}
|= @ "
=
w
| yxO=O ` v |=Q=O "
T} QD=t l} QY=va s=tD
O}vm xHwD Q} R p=Ft x@
"O
wtv h} QaD uwDU
A - matrix(c(1,2,3,4), nr=2, nc=2) A ,1] ,2] 1,] 1 3 2,] 2 4 =F w | =iD Ai,j]
>
w
Q Ovv=t "CU=
Q=O @
Q]U
c() ` =
@ D
2 4 1
Q \U@ T} QD=t `k=w
Q=O @
QY=va
QO
Q CU= |i=m T} QD=t
|= @
<
>
%p t "O W
t xO
U=
O}vm =O}B CUO T} QD=t
R= '
R=
x}QO l} x@ xm O}y=wN@ Qo = uwvm =
A 1,2] 1] 3 >
=F
Ci=} CUO T} QD=t
%p t "
A ,1] 1] 1 2 A 2,] 1] 2 4
R=
|v}at |vwDU =} Q]U x@
w |t
u= D
>
>
Q} R
w x xH}Dv OwW
CQ Y @
=iDU=
xO
dim()
u
w}Uv=t}O `@=D
R=
Qo =
w
CU}v x}=Q l}
A,1]
w |t x_Lqt xm Qw]v=ty
O W
"
dim(A ,1]) NULL
CU=
>
O}vm xHwD O}OH OQ@ Q=m =@ p@k p=Ft x@
"
>
A ,1,drop=F]
"OO
Qov
P
h L
x}=Q C}Y=N =D Owtv
xO
=iDU=
drop
= x@ |v=twoQ
s v
w |t =t=
R= u= D
R |U w x = Q
15
=
} v t v @ u @R
=@ |}=vW
1
pYi
,1] 1,] 1 2,] 2 dim(A ,1,drop=F]) 1] 2 1 >
R = T Q = Q =v xx { matrix(1:6,ncol=3) # Equivalently, enter matrix(1:6,nrow=2) xx ,1] ,2] ,3] 1,] 1 3 5 2,] 2 4 6 =F x wt =iD byrow=T =@ O = O = Q] pm x O Q} O}v x w Q xx { matrix(1:6, ncol=3, byrow=T) xx ,1] ,2] ,3] 1,] 1 2 3 2,] 4 5 6 O}vm xHwD Q} R p=Ft x@ "OvwW|t xQ}NP
"
>
Q V}B |vwDU
Z i
w x
CQ Y @
u @ R QO
} @
U
} D t
Y a
xm O}W=@ xDW=O xHwD
<
>
"
m
H D
>
}R p t
@ "O
v xO
U=
CQ a R=
W @ |
W
@ u W x
wLv xm O}y=wN@ Qo =
NP |x
<
>
"
B { matrix(1:6, nr=2) B ,1] ,2] ,3] 1,] 1 3 5 2,] 2 4 6 B ,2:3] ,1] ,2] 1,] 3 5 2,] 4 6
>
O}vm xHwD Q} R x}=QQ} R x@ uwvm =
<
>
>
"
O}vm xHwD Q} R p=Ft x@ "O}vm
xx { matrix(1:6, ncol=3) xx ,1] ,2] ,3] 1,] 1 2 3 2,] 4 5 6 x { as.vector(xx) x 1] 1 2 3 4 5 6 w dim() w}U =t ` = \ w = >
=iDU=
xO
as.vector ` =
@ D R=
O}QO
Q
w
x@ T} QD=t l} xm O}y=wN@ Qo =
Q=O @ CQ Y
<
>
>
<
>
CQ Y
u
v
}O
@ D
U D Q m
u}=
"O=O
Q}}eD
O
Q
=Q O= a= R= | U
l} pmW
w |t xvwoJ xm O}vm xHwD uwvm =
u= D "
>
x { 1:24 <
O}vm xHwD Q} R p=Ft x@
"O
Q}o|t
1390 '
|vWwOv|wUwt
16
dim(x) { c(2,12) x ,1] ,2] ,3] ,4] ,5] ,6] ,7] ,8] ,9] ,10] ,11] ,12] 1,] 1 3 5 7 9 11 13 15 17 19 21 23 2,] 2 4 6 8 10 12 14 16 18 20 22 24
>
<
>
"
O}vm xHwD Q} R p=Ft x@ q=L
x { 1:24 dim(x) { c(3,4,2) x ,,1 >
<
>
<
>
,1] ,2] ,3] ,4] 1,] 1 4 7 10 2,] 2 5 8 11 3,] 3 6 9 12 ,,2 1,] 2,] 3,]
,1] ,2] ,3] ,4] 13 16 19 22 14 17 20 23 15 18 21 24
Ctqa OQ@ Q=m
=F
O
|t u=Wv
pw= p t " yO
<- Ctqa
=Q
=
w
Ctqa OQ@ Q=m
Cw
=iD xm O}vm xHwD Q} R p=Ft
x@ uwvm =
wO
Q |t xH=wt =]N =@ xm 'CU= T} QD=t u=twoQ
"OO o
=UD
QO |w
matrix(a = 10, 5, 5) Error in matrix(a = 10, 5, 5) : unused argument(s) (a = 10) >
"
matrix(a ,1] 1,] 10 2,] 10 3,] 10 4,] 10 5,] 10
>
CU= T} QD=t u=twoQ
<- Ctqa OQ@ Q=m
QO
=F
swO p t
{ 10, 5, 5) ,2] ,3] ,4] ,5] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
<
"
CW=O R}v =RHt Qw]x@
=Q
a
Okt
Q=
w |t xD@r= "OyO|t u=Wv
u= D
a 1] 10
=Q
5 5 T Q=
} D t
l} x m
>
x@ "Ov}=tv pYDt Qo}Om} x@ uwDU =}
w
Q]U ?UL Q@
=Q
T} QD=t
wO
=}
w
x}=Q
wO
Ovv=wD|t
O Q}o@ Q_v
" }
cbind() rbind() ` w
QO =Q
w
T} QD=t u}rw= p=Ft
@= D
u=
wva
R |U w x = Q
17
=
} v t v @ u @R
m1 { matrix(1, nr=2, nc=2) m1 ,1] ,2] 1,] 1 1 2,] 1 1
>
=@ |}=vW
pYi
1
<
>
"
m2 { matrix(2, nr=2, nc=2) m2 ,1] ,2] 1,] 2 2 2,] 2 2
>
CU= Q} R
w
CQ Y
x@ p=Ft T} QD=t u}twO
<
>
CU= Q} R
"
w
CQ Y
x@ xH}Dv x=ov
w |t p=ta=
'O W
m1, m2
rbind(m1, m2) ,1] ,2] 1,] 1 1 2,] 1 1 3,] 2 2 4,] 2 2
= T} QD=t
| y
|wQ
rbind ` =
@ D u
wvm =
>
CU= Q} R
"
w
CQ Y
cbind(m1, m2) ,1] ,2] ,3] ,4] 1,] 1 1 2 2 2,] 1 1 2 2
x@ xH}Dv x=ov
w |t p=ta=
'O W
m1, m2
= T} QD=t
| y
|wQ
cbind ` =
@ D
Qo =
>
wLv "CU}v |U} wvxt=vQ@ x@ '1
MARGIN
Q]U xOvyOu=Wv
=F x@ "CU= `@=D
p t
=}
=}DN=
|Q
wtv p=ta= uwDU
|R v w O
=
T} QD=t
'
= w
| yu t oQ
...
X Q
w
u QO
Q]U =}
xm 'CU=
=ta= CU=
w OO o p
apply() ` = = apply(X, MARGIN, FUN,...) w x |r Q x C |a = FUN c(1,2) Q = wD
w
Q]U
'u
wDU
|wQ =Q
`@ =D l }
w |t
u= D
@ D
CQ Y
Q= k
m
U=
@ D
'
wO
y } w 2 u "
x { rnorm(10, -5, 0.1) y { rnorm(10, 5, 2) X { cbind(x, y) apply(X, 2, mean) y x -5.027833 4.617558 apply(X, 2, sd) x y 0.1023305 1.8215198 =F wv x apply() ` =
>
<
>
<
>
@
@
m
U
O}vm xHwD Q} R
<
>
>
u |wQ p t u=
a
@
CU= uwDU xU pt=W
@ D "
w |t xO}t=v
w O W
trees x
w
R
m OQ=O O Hw |=xO=O '
=
u @ R QO
Q |t p=ta=
"OO o
apply(trees, 2, sum) Girth Height Volume 410.7 2356.0 935.3 >
1390 '
|vWwOv|wUwt
wtv pta Q} R
"O
18
w
CQ Y wO
x@
w |t 'O}vm x@U=Lt
u= D
=Q
Height
wDU l} `tH ,qFt \ki xm O}y=wN@ Qo = uwvm =
u
sum(trees ,2]) 1] 2356 >
=}
sum(trees$Height) 1] 2356 =iD w |t trees =
wDU s=v
O}v=wN|t =Qi Qwm Pt `@=D =@
= OD@=
w
>
xO
U= u= D
v
| yxO=O u
R=
\ki
wtv
=Q xO=O s v =
"O
xO
u}ov=}t '`tH x@U=Lt
::: w
=iDU=
w |t
u= D
attach()
"O=O s
attach(trees) sum(Height) 1] 2356
=Hv=
Q
w
w
Qy
|= @ j i CQ Y wO
R
= x@
s v
w
=
u @ R QO
|a@=D
Q
= u}=
Q
R= Q m
=}rta =yuwDU s=v =@
= =t=
QO x Nq @
wtv
|= @ "O
w |t TBU
=Q j i C
u= D
w
> >
wtv
"O
=iDU=
xO
names() ` =
w |t
@ D R= u= D
trees
=
| yxO=O
xawtHt pN=O
QO
=yQ}eDt |t=U=
names(trees) 1] "Girth" "Height" "Volume"
OaD
w O=
R= `
q]=
Q
|= @
>
`@=D
=
= w
| yu t oQ
x@ p=Ft
wva x@ "OyO u=Wv =tW x@
u=
=Q
`@=D l}
=
= w
| yu t oQ
Ov=wD|t
args() ` = R
=
@ D
u @ R QO
%xHwD
apply()
O}vm xHwD
"
args(apply) function (X, MARGIN, FUN, ...) NULL >
|W l} Q=DN=U xOy=Wt R=
str ` =
: : : w
=
w |t xO}t=v
@ D s v "O W
`@=wD '=yQ}eDt '=yxO=O
R=
str() x
wtv
m O
=iDU= |a@=D
xO
w |t
R= u= D
sa= |W Qy Q=DN=U Ov=wD|t `@=D u}=
args() names() ` w w
@= D
Q |t |W=v Q=DN=U
"OO o
|
Q@
=vat x@
1 2 4 1
R = structure xtr qa
xw
u @ R QO
O}vm xHwD Q} R p=Ft x@ "OyO u=Wv
"
m
=Q
> str(trees) 'data.frame':
31 obs. of
3 variables:
$ Girth : num
8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
$ Height: num
70 65 63 72 81 83 66 75 80 75 ...
$ Volume: num
10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...
O =Wt
x y
=Q
Q}eDt Qy
=
| yxO=O R=
|DtUk
=
w yxO=O O=
OaD '=yxO=O `wv
w |t =yQ}eDt |t=U=
u= D
OaD Q@
w O=
qa =Hv}=
xw
QO
wtv
"O "
O}vm x=ov
Q
'Gw N
`@=D |va}
q() ` =
=D =
@ D Q N U
x@ p=Ft
u=
wva x@ =}
w
R |U w x = Q
19
=
} v t v @ u @R
=@ |}=vW
1
pYi
str(q) function (save = "default", status = 0, runLast = TRUE) >
u C=}rta w
m1, m2 T Q = Q p = x rbind(m1,m2) %*% cbind(m1, m2) ,1] ,2] ,3] ,4] 1,] 2 2 4 4 2,] 2 2 4 4 3,] 4 4 8 8 4,] 4 4 8 8
O}vm xHwD
"
} D t wO ?
Y L
=F
Q
w |t
@ p t |= @ "O W
=iDU= %*% Qorta
xO
T} QD=t
2 2 4 1
T} QD=t
wO ? |= @
R=
Q
Q
>
=}
cbind(m1, m2) %*% rbind(m1, m2) ,1] ,2] 1,] 10 10 2,] 10 10
w
>
l} uDN=U =}
Q]k
w |
= x
| y }QO
Q}}eD =}
QNDU=
w G=
Q
|= @
diag() ` =
Q |t pY=L
@ D "OO o
t() ` =
@ D
"OwQ
\UwD x}=Q l}
|t Q=mx@
=yv=QD
xO
Q]k T} QD=t
|
diag(m1) 1] 1 1 diag(rbind(m1, m2) %*% cbind(m1, m2)) 1] 2 2 8 8 diag(m1) { 10 m1 ,1] ,2] 1,] 10 1 2,] 1 10 diag(3) ,1] ,2] ,3] 1,] 1 0 0 2,] 0 1 0 3,] 0 0 1 v { c(10, 20, 30) diag(v) ,1] ,2] ,3] 1,] 10 0 0 2,] 0 20 0 3,] 0 0 30 >
>
>
<
>
>
>
<
>
wtv O=H}= u}}=B ErFt T} QD=t =}
"O
> > >
A { matrix(1:9, nc=3) A row(A) col(A)] { 0 A <
>
<
= ErFt T} QD=t
w q @
= T}Ov= w T} QD=t l} uwDU w Q]U
'u | y
=iDU= =@
R= xO
w |t
u= D
1390 '
|vWwOv|wUwt
,1] ,2] 1,] 1 4 2,] 0 5 3,] 0 0 wma Q solve()
T
t |= @
20
,3] 7 8 9 Q
wDUO
=v}tQDO x@U=Lt
'u
|t Q=mx@ xS} w
"OwQ
Q
det()
=
Q
|= @
wDUO
Q
Q}O=kt
| yQ=O @ w
"OQ=O
uOQw
|U} QD=t
C U
CUO@
Q
|= @
eigen()
wDUO
Q
w
T} QD=t
11 Q=O?wJQ=J |=yxO=O w
CU= hrDNt
| yxO=O ` v
=
R
| yxO=O
=
OvtR=}v
w =@
=
=
wDU
| yu
=
=
u @ R QO |Q t | yp=wQ
w
=
=
wtv
uO
3 4 1
CU= T} QD=t \U@ =yxO=O `wv u}= `k=w
QFm = '`k=w
O = |t
QO " W @
R
QO
p}rLD w x} RHD
=
=D =
QO yxO=O Q N U
QO
u} QD?U=vt
O}vm xHwD Q} R p=Ft x@ uwvm = "CU= CUO u}=
R= |OwQw
mtcars
Mazda RX4 Mazda RX4 Wag Datsun 710 Hornet 4 Drive Hornet Sportabout
mpg 21.0 21.0 22.8 21.4 18.7
OvyOV}=tv =yuwDU
w
x
w wQO N
cyl 6 6 4 6 8
disp 160.0 160.0 108.0 258.0 360.0
hp 110 110 93 110 175
l} xOv}=tv Q]U Qy q=@ O
drat 3.90 3.90 3.85 3.08 3.15
pN=O "CU=
Q l}
Q=O @
=tD "OvDUy uwo =vwo
s
wt 2.620 2.875 2.320 3.215 3.440
O
|t u=Wv
wQ =
=
|=Q=O Cw
w =@ |}=yxO=O
=iDt
=
O
=Q Q D= @ Q m O a
u u
| y` v
vs 0 0 1 1 0
CU= hrDNt
12 xOQDUo xLiY l} pFt
wDU Qy "CU=
qsec 16.46 17.02 18.61 19.44 17.02
w
am gear carb 1 4 4 1 4 4 1 4 1 0 3 1 0 3 2
=
pw H QO "
" yO
w
= q]= pt=W =yxO=O u}=
| ywQO N C a
carb Q}eD
=
=F u}=
t p t
=
Q=O? JQ J | yxO=O
Q
| yQ=O @ |wQ "
= C}Y=N
=
w yu
CU= =yQ}eDt
QO "
xm O}vm QwYD O}v=wD|t =tW
Qyx@ =t= "OvQ=O u=Um} `wv QY=va s=tD OvW=@|t Q@=Q@ pw]
=D =
|=Q=O Q N U
Q=O?wJQ=J |=yxO=O X=wN
s v
=
u @R
|=Q=O Q=O? JQ J | yxO=O "
"
>
R
=@ =Lt |=Q@ |Y=N `@=wD
wDU |t=U= pt=W |t=U= C}Y=N "OvW=@ =yQ]U s=v w |t=U=
w
X= N |=Q=O
u}=
Q Qy
Q=O @
QO
=yQ=OQ@
1 3 4 1
Ovv=wD|t =yxO=O `wv u}=
O}vm xHwD Q} R p=Ft x@ "OvW=@|t =yQ]U |t=U= V}=tv =yQ]U
"
rownames(mtcars) 1:5] 1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" 4] "Hornet 4 Drive" "Hornet Sportabout" >
=}
names(mtcars) 1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" 11] "carb" >
11. data frame
12. spreadsheet
w
R |U w x = Q
21
=
} v t v @ u @R
=@ |}=vW
Q=O?wJQ=J |=yxO=O O=H}=
Qo}O
VwQ "
CU= p}=i l} j} Q]
R=
=yxO=O uOv=wN =yu "
R=
|m}
O}vm xHwD Q} R
w
"OQ=O O Hw
=
|irDNt
=
| yx=Q
=F x@ "OW=@|t
| yp t
1
pYi
2 3 4 1
=yxO=O `wv u}= O=H}=
data.frame() ` =
Q
|= @
=iDU=
@ D R= xO
my.logical { sample(c(T,F), size = 5, replace = T) my.numeric { rnorm(5) my.df { data.frame(my.logical,my.numeric) my.df my.logical my.numeric 1 FALSE -0.05643126 2 FALSE 0.21557811 3 FALSE -0.04023551 4 TRUE -0.50746280 5 FALSE -1.63608548
>
<
>
<
<
> >
=}
w
test - matrix(rnorm(21),7,3) test - data.frame(test) test X1 X2 X3 1 -0.9247492 0.18698082 -1.39943435 2 -0.6256957 0.86310566 0.91401401 3 -0.3338215 -0.74399557 0.08866272 4 0.7411739 -0.61656031 0.18208417 5 0.3436381 -0.64038437 -0.76397593 6 -1.0379184 -0.49068270 0.21339323 7 -0.5624376 -0.01380767 -1.69015277
>
<
>
<
>
O}vm
"
=iDU=
xO
=
=F
q @ p t QO
|t=U= C}Y=N
R= u
wvm =
names(test) 1] "X1" "X2" "X3" >
X1, X2, X3 = wD | = = w w x R names(test) { c("Price", "Length", "Income") row.names(test) { c("Ali","Abas","Hamid","Saeed","Amir","Mehdi","Majid") test Price Length Income Ali -0.9247492 0.18698082 -1.39943435 Abas -0.6256957 0.86310566 0.91401401 Hamid -0.3338215 -0.74399557 0.08866272 Saeed 0.7411739 -0.61656031 0.18208417 Amir 0.3436381 -0.64038437 -0.76397593 Mehdi -1.0379184 -0.49068270 0.21339323 Majid -0.5624376 -0.01380767 -1.69015277
O}yO Q=Qk
"
>
> >
w
wNrO |t=U= O}v=wD|t =tW "CU= xO}t=v
=Q O N x=
<
<
=Q yu
U
t U= Q mO N CQ Y @
=
u @R
1390 '
u u
|vWwOv|wUwt
=mt=
w
=
22
=
Q=O? JQ J | yxO=O "O
wtv
xO
=iDU=
= @ xm
=Hv= =yT} QD=t =@
O=O s
as.matrix() ` =
w |t
u= D
|Dw=iDt
=Q
w |t 'T} QD=t x@
=}rta OW x_Lqt ,q@k xm Qw]u=ty
C
w
@ D R= u= D
=
=
V}=Q} w =Q =yv swRr CQwY QO w 'Owtv x_Lqt xOQDUo xLiY l} CQwY x@ =Q Q=O?wJQ=J w |t
"O W
=yQ}eDt u}= "OvyO|t u=Wv
factor = R @
=
u @ R QO =Q
=iDU=
xO
=yv xm OvwW|t u=}@
Q}N= CtUk
QO
|UQ
x =
'|= U t '
O}vm xHwD Q} R
= O x@ uwvm =
| y ) m
O
w
"OQ= v O Hw pw=
w |t
VN@
QO
<
>
<
=
u @ R QO
Q
Q
|= @ "O m
factor() `@=D
4 4 1
w
CQ Y
x@ =yQ}eDt
=yl =N
QO =Q
w |r}N
| k
xm OwW|t
|a@
R=
w
CQ Y wO
w
=F
x@
wva x@
`= v= p t u=
w h}a x@ =yl =N
w | k '
=UL= |a}@] ?}DQD l}
T
soil.types { c("clay","loam","sand","loam","clay") soil.types { factor(soil.types) soil.types 1] clay loam sand loam clay Levels: clay loam sand >
R
= u}=
?DQt Q}e %OvwW|t u=}@
|vW ,qFt 'O} Q}o@ Q_v
w
@= D R= Q m
x wkt =} |=xDUO
O}vm|t x_Lqt xm Qw]v=ty "CU= ?DQt QwDm =i u}= 'O}vm s}UkD "
=
|= r
w
O
| yxO=O u= D
} w
?DQt
::: w
Q
|= @ "OQ= v O Hw
edit() = x() ` w
"
Qo = =t= "OvDUy ?DQt Q}e QwDm =i xm
p}O@D
Q=O? JQ J | yxO=O
>
?DQt CQwY x@ xm O}vm xHwD Q} R p=Ft x@ q=L "CU=
=Wv
xO=O u
=
K]U xU =}
=Q l N
=
w xU
w l N ` v
levels CtU "
k QO
CU=
soil.degrees { c("weak","average","stronge","weak","stronge") soil.degrees { ordered(soil.degrees,levels=c("weak","average","stronge")) soil.degrees 1] weak average stronge weak stronge Levels: weak average stronge
>
<
>
<
>
<
<
=Wv R}v
"O=O u
O
w
|O a CQ Y
x@ =yv
w |t xm "OyO|t u=Wv
u= D
w]U ?}DQD QN Q]U
=Q K
soil.numeric { as.double(soil.degrees) soil.numeric 1] 1 2 3 1 3 >
<
>
|v=tR |QU |=yC}OwHwt w
O
|t p}mWD
" yO
"OQ=O O Hw
=yu
RHt |v=tR
| U
=Q =
Q
QO
xirw-t
Q |t O=H}=
wO "OO o
l} uwDU Qy xm CU=
ts() ` =
O
@ D
=@ |v=tR
=
CU= |N} Q=D
Q
|W
|U} QD=t =}
R
=
u @ R QO
Q =
Q=O @ ' yxO=O
=Ut pY=wi '=yxO=O M} Q=D
|O a | yxO=O R=
"
=
| y| U <
5 4 1
|w
O}vm xHwD Q} R p=Ft x@ uwvm =
"
> >
my.ts - ts(matrix(rnorm(30), ncol = 2), start = c(1987), freq = 12) my.ts <
R |U w x = Q
23
=
=@ |}=vW
} v t v @ u @R
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar
Series 1 -0.39579521 -0.36649473 -0.40674973 0.32428545 0.55310221 -1.03032817 0.70500090 -1.47332244 0.58314662 1.55713060 0.74596283 0.16404647 -0.03516499 -0.18482688 -1.16434845
1987 1987 1987 1987 1987 1987 1987 1987 1987 1987 1987 1987 1988 1988 1988
1
Series 2 -0.9026295 0.2915367 -1.8566028 -0.3488452 -1.6910047 1.3434787 1.4546442 1.6205861 0.6378932 -1.9681021 0.8186411 -1.1321248 -0.1627264 -1.2735001 -1.0717075 13 =yCUQyi
=D =
|Q N U
Qy w `wv Qy pt=W xm OW=@ |D}OwHwt Ov=wD|t CUQyi l} QYva Qy =t= "CU=
=yxO=O hrDNt
= =D =
Q
w |t u}=Q@=v@ 'OW=@
| yQ N U |= @ u= D
|HwQN C}OwHwt
|t Q=mx@
"OwQ
R
=
=
u @ R QO |Q t
O = |t xQ}e
" W @ "
CU= uw}UQoQ
pYi
Q
O
w x W
6 4 1
Q x}@W CUQyi =} w CU}r
Q=O @
Qo}O CUQyi pt=W Ov=wD|t OwN CUQyi l} xH}Dv
|
|HwQN
=
Q =@ = CUQyi =}
| yp=wQ |= @ , r e
|v}@V}B Q}O=kt '=yxOv=t}k=@ '=yQDt=Q=B
=a@ Qt pk=OL `@=D sQi u} QDxO=U xm 'O}vm xHwD
|= @ C
w
CU}r
Q
wtv
"O
CU=
QO "
=iDU=
xO
u R=
x wtHt pt=W ,=@r=e
OQw @ R= |= a
lst() ` =
@ D
|HwQN x@ p=Ft
Q
|= @
x { 1:5 y { x + rnorm(5,0,0.25) z { lst(x,y) z Intercept X -0.1150539 0.9848682
>
<
>
<
>
<
>
1] 0.259665308 -0.339443370 -0.001599916 -0.017131291 0.098509268 1] TRUE ?}W Q=OQ@ Q
R= Z a R=
u
xirw-t u}rw= xm CU= CUQyi l} u}= "CU= xOW xO=O C@Uv
=} xm OyO|t u=Wv OL=w pw] =@ swU
Q CU=yxOv=t}k=@
Q=O @ "
z x lst(x,y) | @
Q
Okt p=Ft u}= QO
Hw N Q=
Q
xirw-t "CU=
R= |Q=O @ swO
<=
O@t
Q}N =} CU= xOW
#
CU=
%
O
QNDU= p@=k hrDNt |t u=Wv
=Q
xm OyO|t u=Wv
=Q
" yO
CU= xDiQ Q=mx@ s=v CtUk
"
13. Lists
QO
=
G=
| yVwQ
z xi w
u}rw=
z
xirw-t $
r -t
R= |=
xO
Q
R= Z a w
=iDU=
<=
O@t
x@ CUQyi l} QY=va
z1]]
xirw-t
%
z name
%
=tW
xirw-t s=v
xQ
1390 '
|vWwOv|wUwt
zr
CiQo xQy@ $
"
24
z residuals
w |t $
R= u= D
=H@ ,qFt
|
wtv
"O
xO
=iDU= R}v
u
QYDNt
w |t s=v
R= u= D
Q =x
Q
uO @ Q m @ |= @
test { z$r test 1] 0.259665308 -0.339443370 -0.001599916 -0.017131291 0.098509268 z$r 4] # fourth element of the residuals 1] -0.01713129 >
<
>
>
CUQyi O=H}= =
= w
| yu t oQ
CUQyi
= xirw-t
| y
|=
wDLt
w
CUQyi
= xirw-t |t=U=
| y
"O
wtv
=iDU=
xO
list() ` =
@ D R=
O}=@ CUQyi O=H}= "
x1 { 1:5 x2 { c(T,T,F,F,T) y { list(numbers = x1, wrong = x2) y $numbers 1] 1 2 3 4 5 $wrong 1] TRUE TRUE FALSE FALSE TRUE x@ Q C R = | l C Q C C y xi w wrong |k]v | = >
Q
|= @
OvDUy CU}r `@=D
<
> >
1 6 4 1
<
<
>
D t "
U=
"
u @R <
U=
swO
W
} u
r -t
U=Q h ] w t <
U=
xirw-t s=v =F
W q @ p t QO "
$
Qorta AJ CtU O}vm|t x_Lqt xm Qw]u=ty
CU= CU=Q x@ AJ
R=
=yu uDiQo Q=Qk ?}DQD x@ xirw-t
y 2]] 1] TRUE TRUE FALSE FALSE TRUE >
"O=O
Q}}eD
=Q
CUQyi |t=U=
w |t "Ovm
u= D
QNDU=
G=
=Q
CUQyi
= xirw-t |t=U= Ov=wD|t
| y
names() ` =
@ D
names(y) 1] "numbers" "wrong" names(y) { c("lots", "valid") names(y) 1] "lots" "valid" >
>
<
>
R
"Ow i= |
Qo}O
= xirw-t
| y
y 3]] { 1:30 y$test { "hello" y $lots 1] 1 2 3 4 5 >
>
<
<
>
valid 1] TRUE TRUE FALSE FALSE TRUE $
3]] 1] 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
w |t |r@k CUQyi x@
u= D
R |U w x = Q
25
=
} v t v @ u @R
=@ |}=vW
pYi
1
26] 26 27 28 29 30 test 1] "hello" $
"
O}vm xHwD xWwQm
wO w
xWwQm l} u}@
Cw
=iD x@ uwvm =
y 1] $lots 1] 1 2 3 4 5 >
y 1]] 1] 1 2 3 4 5 >
xWwQm
wO R=
xm |t=ovy =t= "CU= CUQyi l} OwN
Q |t pY=L xm
OO o
xirw-t
|=
w |t
'O W
=iDU= xWwQm l}
xO
R=
O |t CUO@ xirw-t OwN \ki OwW|t
=iDU=
" }
R |va}
"O
Q
wtv =QH=
Q
O= i= |= @ =Q
w
CWwv
=
wDUO
w |t xm CU= u}= OwN x@=Wt
u QO =Q |=xO U C=Q
|U} wvxt=vQ@ xm CU=
S
u=@ R =@
u= D
=} wYN
|=x } w C Y
|=Q=O
=t= 'CU= QDDUt
u QO
xO
51
|U} wvxt=vQ@
=
R
Q Q@
| yQ= i=s v
|Dkw
R
=
QQ
u @R | D @
|U} wvxt=vQ@ u=@ R l}
= |oS} w
| y
= |t QDu=U XYNDtQ}e
"OR U
CU}v
"
Qo}O
|
C=Q
wDUO
'O
wWv Q=QkQ@
C
=
u @R
Q
\ W
u}t=Qi x@ Cy=@W |@ xm CU= |rQDvm Q=DN=U
u}= Qo =
Q
|=Q=O
R=
=
yu @ R
Q}=U Ovv=t
\QW
1 5 1
Q Q |]QW xm OwW =QH= O}=@ QwDUO l} |Dkw `k=wt
R= |=xQ B QO
w OO o Q= k @
O}vm xHwD
"
Q
=
wDUO |twta pmW x@ "OW Oy=wN =QH=
\ W Q
if (logical exp.) { }
then do this
else {
do this } w |t
"O W
=
A J
T
Q
w |t
h L w O W
x {8 if (x %% 2 == 0) print("T") 1] "T" x ` = |r Q w | =W ifelse() ` = >
@
GwR
s}UkD xOv=t|k=@ 'OW=@
GwR
x Q}eD
t Q=
Okt Qo = Q} R p=Ft
QO
<
@ D
m K W "O W
t xO=O u
v
w
@ D CQ Y
x@ xm Owtv
=iDU= |y=Dwm |rw =Q=m QwDUO
xO
w |t =Hv}=
R= u= D
CU= Q} R
"
w
QO
CQ Y
1390 '
|vWwOv|wUwt
26
ifelse(test, yes, no) =
= w
% yu t oQ "
w |t =QH=
"O W
Q |t =QH=
"OO o
yes no
=ov
x x
=ov
CU= |k]vt
=@ l}
CQ a
w CUQO |k]vt
'O @
w CUQO=v |k]vt
'O @
test yes no
%
=@ Qo =
CQ a
%
=@ Qo =
CQ a
%
O}vm xHwD Q} R p=Ft x@ uwvm =
"
x { c(2:-2) sqrt(ifelse(x = 0, x, NA)) 1] 1.414 1.000 0.000 NA NA >
<
>
>
xkrL CU= Q} R KQW x@
"
u
|rm QwDUO
2 5 1
w |t Q=QmD Q=@ u}OvJ xm CU= |D=}rta
"O W
Q xkrL
|= @
for (i in start:nish) execute task O}vm xHwD Q} R p=Ft x@ uwvm =
"
y { vector(mode = "numeric") for (i 1:10) + y i] { i y 1] 1 2 3 4 5 6 7 8 9 10 >
<
>
f
<
g
>
"
O}vm xHwD Q} R p=Ft x@ "CW=O wD
QO
wD
= xkrL
| y
w |t
u= D
z - matrix(2, 4) for(i in 1:2) + for(j in 1:4) z i,j] - i+j z ,1] ,2] ,3] ,4] 1,] 2 3 4 5 2,] 3 4 5 6 >
<
f
<
g
>
u}= "Owtv
xO
=iDU= x}=Q
=
|=Q m Q
O
=}U@ C}Y=N
|t CUO@
" yO
x { c(1:10) y { x x %% 2 == 0] y 1] 2 4 6 8 10 apply(X, Margin, Function) = pt Function OvDU c(1,2)
>
<
>
<
=Q
wtv
w
R= w O
|Q=OO N
10 = 1 u} D
xkrL
O
@ GwR O= a=
Q
Q =x
w \ W uO @ Q m @ R=
O}=@
'OQ=O u
=mt= xm =Hv =D =t=
Q} R p=Ft "OW=@|t xkrL |awv utDt OwN C}Y=N
>
w
CQ Y
} w
a
w
y
wO
apply T Q= X
x@ QwDUO xwLv "Ovm|t sm Q=}U@ =Q xkrL R= xO=iDU= swRr
Qy =}
w
(2) =
wDU
yu
(1) =
'
y
Q]U
Margin
w
CU=
} D t
w |t p=ta= =yxO=O
"O W
|wQ
Q}_v |a@=wD CU=
u QO "
xm CU= |a@=D
R |U w x = Q
27
=
} v t v @ u @R
=@ |}=vW
1
pYi
x { rnorm(10,-5,0.1) y { rnorm(10,5,2) X { cbind(x,y) apply(X, 2, mean) x y -5.022379 4.021949 apply(X, 2, sd) x y 0.07029347 1.73544377
>
<
>
<
>
<
>
>
`@=wD "
CU= Q} R KQW x@ `@=D l} uDWwv |twta QwDUO "OyO|t s=Hv=
functionName { function(arg1, arg2, do this
)
<
=Q
|Y=N xi}_w xm CU= xt=vQ@
3 5 1
VN@ l} `@=D
R=
f
g
|t u=Wv
O
" yO
w =F}i x}k xm CU= |a@=D Q} R p=Ft
=Q EQ e
hypot - function(a, b) sqrt(a^2 + b^2) hypot(3,4) 1] 5 >
<
>
"
3, 4
w |t xDN=U
"O W
O |t CUO@
" }
w |t
"O W
"
>
Ovm|t x@U=Lt
=Q
P
h L
=yxO=O Q=}at
5
CU= xHwD QwNQO Q} R
O
O a
a, b C w QLv=
w
a, b |D w
= Q}eDt
=Lt =@
h} QaD 'OW s=tD x@U=Lt |Dkw
O= a=
=@
w xt=vQ@
k t | y
sqrt(a^2 + b^2) x@
k t
h=
O
w
OQ= t j i
U
u}ov=}t xm O} Q}o@ Q_v
QO =Q
Q} R `@=D
QO
%p=Ft
mystats { function(x) <
+ + mymean { mean(x) + mysd { sd(x) + c(mean=mymean,sd=mysd) + f
<
<
g
Q |t xH}Dv Q} R Q}O=kt OwW
"OO o
> my_data <- c(1,2,3,4,5) > mystats(my_data) mean
sd
3.000000 1.581139
w `@=D x@ Q} R
xO=O j i
=
| yxO=O
Qo =
1390 '
|vWwOv|wUwt
28
w |t xDiQo Q=mx@
"O W
>
R
=
u @ R QO
list() ` =
@ D R= xO
=iDU= =@ `@=D u}ty
mystats { function (x) <
+ + myinput { x + mymean { mean(x) + mysd { sd(x) + list(data = myinput, mean = mymean, sd = mysd) + f
<
<
<
g
Q |t xH}Dv Q} R Q}O=kt OwW
"OO o
w `@=D x@ Q} R
=
xO=O j i
| yxO=O
Qo =
> my_data <- c(1,2,3,4,5) > mystats(my_data) $data 1] 1 2 3 4 5
$mean 1] 3
$sd 1] 1.581139 |Q=}DN= w |Q=@H= u=twoQ
CU= |Q=}DN= l} s=Om
"
=Q
2
Q V}B Q=Okt
Z i
w
=@
= w
O xm Ovm|t u}at `@=D h} QaD 'OwW|t xOv=wN=Qi
w |Q H= u t oQ s= m
CU=
=}DN=
|Q
k
= w
u t oQ w
OyO|t =]N `@=D OW=@v Qo =
w
CU=
R
=@
|Q H=
=
u @ R QO
x
1 3 5 1
`@=D l} |Dkw
= w
u t oQ
Q} R p=Ft
QO
"OQ=O
power { function(x, k=2) + x^k + power(5) 1] 25 power() Error in power() : element 1 is empty the part of the args list of '^' being evaluated was: (x, k) >
<
f
g
>
>
"O
power(5,3) 1] 125 >
wtv u}at
=Q
|Dw=iDt Q=Okt
k
= w
Q
w |t =t=
u t oQ |= @ u= D
R |U w x = Q
29
=
} v t v @ u @R
=@ |}=vW
: : : u=twoQ
|mJwm `@=D O}y=wN|t O}vm
Q
w
=iDU= Qo}O `@=D x@ `@=D l}
Z i "O W xO
=
= w
Ovm sUQ
pYi
2 3 5 1
Q Ov=wD|t x]kv xU u=twoQ
| yu t oQ p "
>
=kDv=
1
|= @
xup = 0 D
R= =Q T
wv}U `@=D xm O}U} wv@
plotsin - function(xup=2 pi,...) <
+ + x - seq(0, xup, l=100) + plot(x, sin(x), type="l",...) + plotsin(col="red") f
<
g
> Q
w@Ht xm
O
Q P |t
u uw @ O } B
=Q
Q}=U
w
xlab lwd col Q}_ plot ` = '
'
v
w |t xm
@ D QO u= D
|v=twoQ Qy
=Q
plotsin ` =
O}vm XNWt
"
<<- |v=yH
`@=D Qo = ,=vt
=Q u
CL=QY x@ xm u}= Qot 'CU= |rLt Q}eDt
w |tv u} Ro}=H Vt=vsy Q}eDt
"O W
O =
u
O}}=tv
Okt `@=D
|wQ VQ=
?
=
Q}F-=D `@=D
QO |
Q
Q |t
|= H= "OO o
=UDv= l} `@=D QwDUO u} QN xm
3QQ x @= @
Okt `@=D pN=O
Q=
Okt
=Q |Q=
|
|rLt Q}eDt Qo}O
u
Qot
3 3 5 1
QO
=@ x@ "O}vm h} QaD
CQ a
|t u}@
R= u Q=
x Q}eD
OD@= 'Q} R p=Ft
OwQ
Q}o|t QiY Q=Okt
QO "O
xm O}W=@
Q}eDt x@ Qo = `@=D pN=O
R= GQ N '
" W @ ?
Q}eDt
wUvt
@ D
@ D QO =Q u
|rLt |=yQ}eDt
plotsin ` =
t =
Okt O@=} xtD=N QO
P |tv |vwQ}@ |v=yH
"OQ= o
x {0 functionx - function() +x {3 + functionx() x 1] 0 >
<
>
<
f
<
g
> >
w |t h} QaD |v=yH
"O W
x {0 functionx - function() +x {3 + functionx() x 1] 3 >
w
CQ Y
x@ q=@ p=Ft uwvm =
<
>
<
f
<<
g
> >
O}vm xHwD Q} R p=Ft x@ '`@=D l} |DL 'OW=@ |W Qy Ov=wD|t `@=D u=twoQ
"
>
test { function(n, fun) <
+ + u { runif(n) + fun(u) f
<
1390 '
+
|vWwOv|wUwt
30
g
test(3,sin) 1] 0.7537332 0.8033265 0.3290288 >
Q@ Q=m xOW h} QaD Qorta l} CN=U Qmrta x@ p=Ft
O
Q
`w W R=
p@k
w |t
"O W
=iDU=
xO
Ctqa
&
= u}=
Q CN=U
R= Q m
|= @ "
=Q
Q_v
4 3 5 1
R = setdi() union() ` w
w Qorta
OQ t
O}vm xHwD
"
w |t
u= D w
u @ R QO @= D
x { c(1,2,5) y { c(5,1,8,9) union(x,y) 1] 1 2 5 8 9 setdi(x,y) 1] 2 setdi(y,x) 1] 8 9 >
<
>
<
>
>
>
"
Ovm|t x@U=Lt
sdf%" { function(a,b) + sdfxy { setdi(x,y) + sdfyx { setdi(y,x) + union(sdfxy,sdfyx) + x %sdf% y 1] 2 8 9
>
"%
<
uQ
=kDt
w
CQ Y
x@
=Q
xawtHt
qDN= xm OwW|t xDN=U
wO h
Qorta uwvm =
|
f
<
<
g
>
=Wv
u
=Q wO
Qy Q=m xwLv Q} R p=Ft '15 |DWoR=@
VwQ w
O
14 Q=QmD
|t u=Wv
" yO
VwQ "
z 0 >
CU= swUQt OQm} wQ Q
= Q
|= @ =Q p t v p
wtat C=@U=Lt |=Q@ %p=Ft
wO ,q
=tDL= OOa x@U=Lt Q} R pwtQi "OyO|t
1 ( 1)n 2n+1 X 1 1 ( ) = 2 + 2 n=0 !2n (2 + 1) z
;
p
"
z
n
n
CU= Q} R MQW x@
= O xm OwW|t p=@vO Q=QmD
u | y m
Phi1 { function(z) sum = z nfac = 1 for (n in 1:30) nfac = n nfac sum = sum + (-1)^n z ^ (2 n + 1) / (nfac 2^n (2 n + 1)) 0.5 + sum / sqrt(2 pi) >
<
VwQ pw=
f
f
g
g
Phi1(1.96) 1] 0.9750021 >
w |t x_Lqt Q} R
"O W
14. iteration
15. recursion
QO
|DWoR=@
VwQ
x@ q=@ xr=Ut
R |U w x = Q
31
>
Phi2 { function(z) <
f
n2p1 = 1 mult = -z^2/2 term = z sum = term for (n in 1:30) n2p1 = n2p1 + 2 term = term mult / n sum = sum + term / n2p1 f
g
0.5 + sum / sqrt(2 pi)
g
Phi2(1.96) 1] 0.9750021 >
=
} v t v @ u @R
=@ |}=vW
1
pYi
swO pYi
Q=O
C=Q
wDUO 'O}vm x_Lqt
=Q
CU= OwHwt =yQ=Owtv sUQ
"
=yu
R=
wt s v
|WN@ O}v=wD@ xm u}=
Q `@=D xvwo
|= @
R
wO
=
u @ R QO "
"
Q
|= @ "O
Ov}=tv O=H}=
Ov}=Ri=}@ OwHwt
O
wtv sUQ
O}vm A}=D
Oy=wN x}=Q= =yu
R
QO =Q
=Q
|Dw=iDt
R = demo(graphics)
'
R
@ D 'OQ=O
Q =v Ovv=wD|t xm 2 u}}=B K]U `@=wD
=
wtv sUQ
u @ R QO Q=O
wtv sUQ Vv+m =QB
> >
wDUO =@ |}=vW
C=Q
`@=wD
Q
|= @
12
s}UQD QO |v=w=Qi OQ@ Q=m xm |a@=D "OOQo|t x_Lqt |Q=Owtv |q=@ K]U `@=wD R= |O=OaD CtUk u}= QO "O
>
u @ R QO
wtv Ovv=wD|t xm 1 q=@ K]U `@=wD
|Q=Owtv
plot() ` =
w |t
u= D
=Q | Y a
OaD
R= |O=
wtv } w
OO
Q=O
=
| yQ=O
demo(persp) =
=Q | } H Q=O
wtv x@
"
" W
UQ
x { rnorm(50) y { rnorm(50) plot(x,y)
Q=O
wtv l}
w |t
u= D
< <
1. high-level plotting functions
2. low-level plotting functions 32
Q
=iDU= =@ Q} R p=Ft
|Q=O @ |xO=O wO R= xO
QO "
CU=
wtv sUQ
33
wva l}
w |t 'O}vm xi==
u= D
=Q
Q} R u}}=B K]U QwDUO Qo = xm
Q |t pY=L Q} R pmW
"OO o
w
wDUO
2
pYi
|= H= R=
TB
CW=O pmW
|= @
j i C=Q
Q
0 −2
−1
y
1
2
u=
Q=O
−2
−1
0
1
x
Vv+m =QB
wtv l} V}=tv
Q=O
%12
pmW "
>
=@
title("Figure 1")
'=Q
=ypmW Qo}O
w
> > > >
w |t =t= "CU=
`= v= u= D
O}vm xHwD Q} R
"
>
= s}UQD
| y
w
x]kv
|=
=yO)m x@
Q V}B
Z i
w Q}=U
OQ= t
w x O
CQ Y @ x W
Q
|= @ u
wvm = "CW=O
s}UQD pmW 'O}vm|t x_Lqt xm Qw]u=ty
plot() ` =
@ D QO
> > > >
> > > >
=
=iDU=
Y N R= xO
< <
CU= q=@
| y ) m |= H=
= O
Q
xH}Dv
3 2
pmW
CU= q=@
| y ) m |= H=
= O
Q
xH}Dv
42
pmW
x { seq(-5,5,1) y { x^2 par(mfrow=c(1,2)) plot(x,y, type='c') text(-0.5,20,"type='c'") plot(x,y, type='h') text(-0.5,20,"type='h'") < <
"
>
type C}
x { seq(-5,5,1) y { x^2 par(mfrow=c(1,2)) plot(x,y) text(-0.5,20,"without type") plot(x,y, type='b') text(-0.5,20,"type='b'") "
>
Q
x { seq(-5,5,1) y { x^2 par(mfrow=c(1,2)) plot(x,y, type='l') text(-0.5,20,"type='l'") plot(x,y, type='o') text(-0.5,20,"type='o'") < <
1390 '
|vWwOv|wUwt
34
0 −2
−1
y
1
2
Figure 1
−2
−1
0
1
x
wva =@ Vv+m =QB
u=
wtv l} V}=tv
Q=O
pmW
%22
CU= q=@
| y ) m |= H=
CU= q=@
| y ) m |= H=
"
> > > > >
= O
Q
xH}Dv
52
pmW
= O
Q
xH}Dv
6 2
pmW
x { seq(-5,5,1) y { x^2 par(mfrow=c(1,2)) plot(x,y, type='s') text(-0.5,20,"type='s'") plot(x,y, type='S') text(-0.5,20,"type='S'") < <
"
curve() `@=D "
CU= Q} R
w
CQ Y
x@
u
|rm pmW "O}=tv sUQ u}at xrY=i l}
|wQ =Q
xDUw}B `@=wD Ov=wD|t
R
1 1 2
=
`@=D u}=
u @R
curve(expr, from, to, add = FALSE, ...) =
= w
Q
% yu t oQ K W
CU= xOW xDWwv
"
Q sUQ
"OO o
u |wQ
O}vm sUQ
"
>
L
O}=@ `@=D xm CU=
TRUE 2 =0
w |t xi== Q=L pmW x@ `@=D pmW OW=@
"O W
x ?U
D
Qo =
w
xvt=O
|=
CU=
%
%
t %
Q=O
wtv
%p=Ft
=Q u 72
pmW
wv}U `@=D
R= =Q T
curve(sin(x), from=0, to=2 pi)
O
|t u=Wv
" yO
O}vm sUQ
"
>
expr from, to |k]v add
Q@ xm |DQ=@a
curve(dnorm(x), from=-3, to=3)
3 = -3 D
O =D
= Q `@=D
R= =Q OQ= v U= p t v
Q=O
wtv
%p=Ft
wtv sUQ
pYi
=Q u 82
pmW
25 15
20
type=’b’
0
5
10
y 0
5
10
y
15
20
without type
−4
−2
0
2
4
−4
−2
x
0
2
4
2
4
x
type='b' =
wtv V}=tv
%32
pmW
25
25
@ Q=O
15
20
type=’h’
0
5
10
y 0
5
10
y
15
20
type=’c’
−4
−2
0
2
4
−4
−2
x
0 x
type='h' type='c' = w
wtv V}=tv
@ Q=O
%42
pmW
O
|t u=Wv
" yO
Q} R
2
Q=O
25
35
= O x@
| y ) m
Q |t xi==
"OO o
Q wDU}y x@ CU= xOW x}yD
u s= o
curve() ` =
@ D
\UwD xm p=tQv p=tDL= `@=D =Hv}=
QO
%p=Ft
O}vm xHwD
"
> > > > >
set.seed(1) x { rnorm(10000) x x -3.5 | x 3.5] { NA hist(x, freq=F, breaks=30) curve(dnorm(x), -3.5, 3.5, add=T) <
<
>
<
O
|t u=Wv
" yO
=Q u 92
pmW
|vWwOv|wUwt
25
36
25
1390 '
15
20
type=’o’
0
5
10
y 0
5
10
y
15
20
type=’l’
−4
−2
0
2
4
−4
−2
0
x
2
4
2
4
x
type='o' type='l' =
wtv V}=tv
%52
pmW
25
@ Q=O
25
w
15
20
type=’S’
0
5
10
y 0
5
10
y
15
20
type=’s’
−4
−2
0
2
4
−4
−2
0
x
x
type='S' type='s' = w
wtv V}=tv
pmW
%62
@ Q=O
|Q=t |Q=Owtv "OQ=O
|v=w=Qi OQ@ Q=m xm
wtv
'O
xO
=iDU=
=
|Q t Q=O
wtv `@=wD
`@=wD w |t
R= u= D
x
Q =y
"OQ=O Q= k
wLt
Q
= Q
=
|wQ p t v | yl
OvJ xm "Ovm|t O=H}= QwLt Ovm|t sUQ
"
O =tv|t O=H}=
" }
=Q
wO |wQ =Q
y ?U
L
Q@
=Q
=ylOvJ `@=D u}=
x
l
box & whisker
OvJ `@=D u}= wtv `@=D u}=
Q=O
R
=
u @ R QO
hist(x) %qqnorm(x) %qqplot(x,y) %boxplot(x)
Ovm|t O=H}= s=QowDU}y `@=D u}=
"
2 1 2
%
O}vm xHwD Q} R p=Ft x@ uwvm =
"
> >
x { rnorm(100) y { rt(100, df=3) < <
wtv sUQ
Q=O
pYi
2
0.0 −1.0
−0.5
sin(x)
0.5
1.0
37
0
1
2
3
4
5
6
%72
pmW
x
sin( ) ` = x
> > > > >
@ D
V}=tv
par(mfrow=c(2,2)) hist(x, col=2) qqnorm(x) qqplot(x,y) boxplot(x, col="green") s}UQD xLiY uwo =vwo |=yCtUk
3 1 2
xr}Uwx@ OwN x@ wv x@ R}v x}L=v u}= w CU= xOW x]=L= Q=Owtv x}L=v \UwD xm s}UQD x}L=v "CU= x}L=v xU pt=W Q=Owtv l} s}]vD s}_vD
oma QD mar QD
= =@ |HQ=N |W=wL "OyO|t u=Wv |@ wNx@
t=Q B
= =@ CU=
t=Q B
xO
wtv x]=L=
=Q
=Q
?r]t u}= Q} R pmW "CU= xO}OQo x]=L= x}W=L Q=yJ
s}UQD x}L=v xm |W=wL "CU= QiY Q@=Q@ =yu
Q V}B Q}O=kt xm
Z i
Q |t
OO o
w |t
"O W
xLiY l} |wQ Q=Owtv OvJ
multiframe
xS=w
hiNt
mf
Q
mfcol = mfrow = QD = =iD = Ovv | =} wD col Q] row C
wtv OvJ xLiY l} |wQ u=wD|t
"O=O Q= k =Q Q=O
O w |t s}_vD Q} R KQW x@ QDt=Q=B
" v W
wO
Qy
"
m
}w
Q |t sUQ
=Q OO o
wtv
Q=O "
O}vm xHwD Q} R p=Ft x@ "CU= u}twO
w
OyO|t
X
layout() ` =
=YDN= OwN x@
u QO
xm
xLiY
|=
xLiY
| yu
CU= |vwDU u=tO}J Qov=}@
Ovm|t s}_vD pmW xLiY
@ D '
=Q
=
= pt=m xiYv
|q @
O Q}o|t
" v
=
| y
t u @ =Q u
par(mfrow=c(r,k)) par(mfcol=c(r,k)) |m}i=Qo QDt=Q=B "OyO|t u=Wv
wDU
mfcol
|wQ =Q
OaD
O=
U
k
w
t=Q B R= xO
w
U
=yQ]U
Q]U u=tO}J Qov=}@
QO l
QDWt Qw]x@
QO Q=O Q=O
U=
u QO
xm
mfrow
Q h]avt
| D
wtv u}rw= "Ov=xOW s}UQD xLiY l}
xLiY u}}=B CtUk
r
w |
=yQ=Owtv u=tO}J xm
U= @
w
OaD
O=
Q=O
| H
4 1 2
VwQ
wtv xU xm
wtv u}twU
w
|vWwOv|wUwt
38
0.2 0.0
0.1
dnorm(x)
0.3
0.4
1390 '
−3
−2
−1
0
1
2
%82
pmW
3
x
O =D
= Q `@=D V}=tv
OQ= v U= p t v
layout(matrix(c(1,2,1,3),2,2)) plot(rnorm(100), type="l") hist(rnorm(100)) qqnorm(runif(100))
> > > >
u}= x@
QO "O
wtv x}=Q=
O
=H}=
=Q x W O
QDW}@
=Q |
Ov@s}UkD
|
=
layout() ` = Q layout.show() ` = = =vt
=F
w |t
| yp t u= D
w |t
u= D
w |t xH}Dv Q} R pmW
@ D |= @ "O W
@ D
@ ,
Q |t XNWt QDy@
w OO o
w
wDUO
j i C=Q
Q
|= H=
=@
Ov@s}UkD xwLv =yp=Ft
|
CW=Po V}=tv
"
=F
%1 p t
> >
layout(matrix(1:4, 2, 2)) layout.show(4)
1
3
2
4
=F
%2 p t
> >
layout(matrix(1:6, 3, 2)) layout.show(6)
1
4
2
5
3
6
=F
%3 p t
wtv sUQ
39
Q=O
2
pYi
0.0
0.1
0.2
Density
0.3
0.4
Histogram of x
−3
−2
−1
0
1
2
3
x
u
> >
x@
w Q
Q wDU}y
\ @ t s= o
O =D
= Q `@=D V}=tv
w OQ= v U= p t v
%92
layout(matrix(1:6, 2, 3)) layout.show(6)
pmW
1
3
5
2
4
6
=F
%4 p t
> >
1
layout(matrix(c(1:3, 3), 2, 2)) layout.show(3)
3 2
=F
%5 p t
m { matrix(1:4, 2, 2) layout(m, widths=c(1, 3), + heights=c(3, 1)) layout.show(4) >
<
>
1
3
2
4
>
u=tRsy
QHvB u}rw=
x
w
R
=
w |t xO=iDU=
u @ R "O W
windows() ` =
= u}= |=Q@ "CW=O sy =@ ,=t=wD
@ D R= Q m
wWo xQHvB l} O}=@ |Oa@ Q=Owtv |=Q@ =yDvt "Ovm|t R=@
O W xO
|m}i=Qo xQHvB OvJ O=H}=
hist() = plot() pF } w
"
O}vm xHwD Q} R p=Ft x@
t
5 1 2
w |t =Q |m}i=Qo xQHvB OvJ
u= D
|D=QwDUO =@ OwNx@OwN =Q |m}i=Qo |t CUO
"OwQ
R=
|r@k
wtv xvQow
Q=O
1390 '
|vWwOv|wUwt
40
Normal Q−Q Plot
2 1 0
0
−2
−1
Sample Quantiles
15 10 5
Frequency
20
Histogram of x
−3
−2
−1
0
1
2
−2
−1
0
1
2
Theoretical Quantiles
0 −2
−5
−1
0
y
1
5
2
x
−2
−1
0
1
2
x
=
|Q t Q=O
wtv OvJ V}=tv
%102
pmW
Outer margin 4
Outer margin 2
Outer margin 3
Plot region
Figure region
Outer margin 1
Q=O
> > > > >
wtv
= VN@ V}=tv
| y
%112
pmW
x { rnorm(50) y { rnorm(50) hist(x) windows() plot(x,y) < <
|HQ=N |=ys}_vD
plot(x,y, col=2)
=F
Q O
p t |= @ " yO
|t u=Wv
O Ov=wD|t QDt=Q=B u}= Q=Okt
w O a
Q u}}aD
"O m
=yQ=Owtv
Q u}}aD
=Q Q=O
wtv
QO xO
"O m
QDm =Q=m =}
=Q
=Q =Q Q=O
wtv
R=
QD|} RH
QDW}@
w]N Ct=N
\
=iDU=
w
w
= QDt=Q=B 'Q} R CUQyi
| y
w |t QDt=Q=B u}= =@
u= D
w]N `wv
OQ t \
6 1 2
w |t QDt=Q=B u}= =@
u= D
lty="dashed"
=F
Q O =
p t |= @ " W @
lwd %lty
%
wtv sUQ
Q=O
pYi
2
−3
−2
−1
0
rnorm(100)
1
2
41
0
20
40
60
80
100
Index
Normal Q−Q Plot
0.8
0
0.0
0.2
0.4
0.6
Sample Quantiles
5
10
15
Frequency
20
25
1.0
Histogram of rnorm(100)
−3
−2
−1
0
1
2
3
−2
rnorm(100)
=
Q O = QDm =Q=m =}
p t |= @ " W @
wtv OvJ V}=tv
O Ov=wD|t QDt=Q=B u}= Q=Okt
wLt u} w=va nvQ Q}}eD
Q
w
"
w
u}= 'q=@ K]U `@=wD R=
=
xD@r=
Q u}}aD
"O m
R= u=
t xO
wtv nvQ
Q=O
Q XNWt
"O m
a } R w u=
U=
Ovm|t u}at
p}O@D `@ Qt x@ xQ}=O xv=Wv ,qFt
|=xQ B QO
1
2
pmW
col.sub col.main wv Q w | =iD col.axis
|= @ '
"O W
"O W
%122
w O a
R= yQ
0
Theoretical Quantiles
|Q t Q=O
col = =F col.lab =
−1
wtv
= xDWwv *srk QDt=Q=B u}=
=Q Q=O
| y
wtv u}at
=Q Q=O
"O
wva nvQ Q}}eD
=yQwLt nvQ Q}}eD
R=
wtv
= x =Wv
| y v
col
w |t QDt=Q=B u}= =@
%
u= D
"red"
Q
|= @ "
Q Q
=
|= @ x Nq @ w
O
font = u = %pch %xlab, ylab Okt
%
|O a Q=
w |t QDt=Q B
u= D
=YDNt |=yQwLt |t=U= u=wD|t QDt=Q=B u}= =@
=Q C
}=
@
w |t s=Hv= OwNx@OwN pta
"O W
w |t Q=m u}=
R= u= D
high
w
Q
|= @ "O
pk=OL Q=Okt
wtv u}}aD
low
u QO
=Q
xm
y x w
wtv
'O
= wLt QFm =OL
| yQ
=iDU=
xO
w
pk=OL Q}O=kt
w |t QDt=Q=B u}= =@
ylim=c(low,high) xlim=c(low,high) w
O
" yO
w
cex.main
R=
O}vm
CiQo ltm
u= D
"
QY=va pt=W
R
nQ @ =Q u=
w |t
wva
cex.lab
O O}y=wN@ Qo =
xR= v=
R=
=yQwLt |t=U=
x =Wv =} w uDt 'x]kv Qy xm
|= v
wtv QDoQR@
"O
wtv QDoQR@
uO
w x OvwW s}_vD
|Q ] @
wtv uwDt
=Q Q=O
Q O}vm
|= @ "
Q
=Q
w |t R}v xv=o =OH
QFm =OL Q=Okt
w |t QDt=Q=B u}= =@ R= u=
w x Ovv=wD|t |m}i=Qo
u= D
wDUO
C=Q
u= D
cex.sub
|Q=O @ CQ Y @
wtv pta
"O
= x =Wv
w y v
=iDU=
xO
|t u=Wv
xlim, ylim
%
u= D
wvaQ} R
Q
|= @
= QDt=Q=B
| y
w x =t=
CQ Y @
cex
%
Q |t
"OO o
=
R= |=xQ B
Q
Q=O @
1390 '
|vWwOv|wUwt
42
u}}=B K]U `@=wD R= |=xQ=B u}}=B K]U `@=wD \UwD Q=m u}= "O}vm xi==
x@
u
w
|a@ xm O}y=wN|t TBU 'O}vm|t O=H}=
=Q OQ= t R=
7 1 2
wtv l} =tW
Q=O
CU= Q}PBu=mt=
"
\w]N uOwRi=
x@
Q
=kv
=Q |OwQw Q=O @ \
lines() ` =
w |t
@ D "O W
O}vm xHwD Q} R p=Ft x@ "Ovm|t s}UQD
"
=Q
xO
=iDU= OwHwt
u}at <=O@t
wtv x@
Q=O
Q
R= Z a w
w]N
\
?}W =@ CU=Q
plot(c(-2,2),c(-2,2)) lines(c(0,2), c(0,2), col="red") abline(a=1, b=2, lty=2) # adds the line y = a + bx abline(v=1, lty=3, col="blue", lwd=3) |k \ h QD = = wt \ v QD = = abline() ` = O |
R
abline() lines() ` w abline() ` = Ov | p s Q
uOw i= |= @
w]N
\
w
@ D "
@= D
m
t
Yw
y
Q
=@
> > >
>
N
t=Q B
@ w |O
a
N
t=Q B
@
@ D QO " }
t
CUO@ Q} R
wtv
Q=O
w
wDUO
j i C=Q
|= H=
0 −2
−1
c(−2, 2)
1
2
i=
−2
−1
0
1
2
c(−2, 2)
CU=Q \N OvJ V}=tv
%132
pmW Q |t sUQ
"OO o
p@k
wDUO x@ p=Ft
C=Q
wva x@
u=
"OwQ
|t Q=mx@ \N xa]k
w u
=m}B s}UQD
Q ?}DQD x@
|= @
segments() arrows() ` w w
w |t xi== Q} R
"O W
arrows( + c(0,0,0), + c(1,1,1), + c(0,0.5,1), + c(1.2,1.5,1.7), + length = 0.1) >
@= D
wDUO
C=Q
wtv sUQ
Q=O
2
pYi
0 −2
−1
c(−2, 2)
1
2
43
−2
−1
0
1
2
c(−2, 2)
=m}B OvJ V}=tv
u
%142
pmW
=yxv=Wv w \=kv uOwRi= "
> > >
Ovm|t xi== |r@k
wtv x@
Q=O
=Q
|]=kv Q} R
= O O R |t OwHwt
| y ) m " }= i=
Q=O
wtv x@
=Q
|i== xv=Wv
w \
=kv
points() ` =
@ D
points(rnorm(4), rnorm(4), pch=3, col="blue") points(rnorm(4), rnorm(4), pch=4, cex=3, lwd=2) points(rnorm(4), rnorm(4), pch="K", col="green") O
|t u=Wv
" yO
Q
=Q O=O Q= k xO
=iDU=
w
w |t xm |}=yxv=Wv
OQ t u= D
R=
|DUQyi Q} R xt=vQ@
plot(0:10, 0:10, type="n", xlab="", ylab="") k { -1 for (i in c(2,5,8)) + for (j in 0:9) + k - k+1 + points(i, j, pch=k, cex=2) + > >
<
>
f
f
<
g
g
Q |t O=H}=
"OO o
162
pmW q=@ xt=vQ@
Q
|= H=
=@
uDt w u=wva uOwRi= = O Ov}=tv|t xi== =Q |vwDt s}UQD x}L=v QO \ki OwHwt Q=Owtv x@
| y ) m "
text() mtext() legend() title() ` w w
'
Ovm|t xi== |r@k
"
> > >
title(main="My title", sub="My subtitle") text(0,0, "some text") text(1,1, "Angular text", srt=45)
'
Q=O
wtv x@
@= D
=Q
|vwDt Q} R
|vWwOv|wUwt
1
2
44
K
0 −1
K
−2
−1
0
1
2
c(−2, 2)
%152
pmW
2
4
6
8
10
x]kv OvJ V}=tv
0
c(−2, 2)
KK
−2
1390 '
0
2
4
=yxv=Wv V}=tv
6
%162
8
pmW
10
wtv sUQ
45
Q=O
Ovm|t xi== OwHwt
"
mtext("Text in the margin", side=4) O Q = = wL 3 O A wL 2 O O a x Nq @ w q @ Q
t
O a '
J Q
t
O a '
wtv |W=wL
Q=O
u}}=B QwLt
Q
u |= @
1
R=
|m} x@
O
O a "
Q_v
=Q
w uDt 3
OQ t
Ovm|t u}}aD
=Q
Q_v
Ovm|t XNWt
CU=
0
Q V}B "Ovm|t u}at Q_v
u Z i
O
" yO C=Q
expression() ` = O}U wv demo(plotmath) wD R \}L
wDUO "O}vm
O}vm A}=D =Q
"
xO
=iDU=
@ D R=
Q
}
UO '
@ =Q
|v=vw}
=
t QO yu
|t u=Wv
=@ir=
|
=
w
wLt
OQ t Q
w \N
j i
=
R= =Q
|wQ =Q
w Q
w |t xi== p@k
"O W
wLt
4
:line =YDN :at
xDWwv xrY=i
xDWwv
C
|wQ
LATEX
C=Q
wtv x@ xm 'O}vm xHwD Q} R
Q=O
:side
CU=Q QwLt
wtv l}
w xO U | yp t i Q=O
pt=m CUQyi uDi=} |=Q@ "CU=
@ D
w
=Q
pYi
mtext() ` =
OQ t Q
" "
2
t
O}y=wN@ Qo =
wDUO x}@W u = O x@ uwvm =
| y ) m
text(-1,1.5, + expression( + paste( + frac(1, sigma sqrt(2 pi)), + " ", + plain(e)^frac(-(x-mu)^2, 2 sigma^2))), + cex = 1.2) >
=yQwLt pQDvm Q |t O=H}= =yZQiV}B
"OO o
=iDU= =@ OwNx@OwN =yQwLt |=y?UJQ@ w =yQwLt 'O}vm|t O=H}=
R= xO
=F x@ "OvwW|t hPL =y QwLt
p t
axes = F
R= xO
wtv =tW |Dkw
=Q |Q=O
=iDU= =@ ,qFt "Owtv pQDvm |m}i=Qo |=yQDt=Q=B =@ u=wD|t =Q C=t}_vD u}= "
> >
O}vm xHwD Q} R
x { rnorm(100) y { rnorm(100) < <
w |tv sUQ OwNx@OwN =yQwLt
"O W
>
plot(x,y, axes=F)
w |t
"O W
> >
Q
OQ=w
|DUO Qw]x@ =yQwLt
axis(side=1) axis(side=2) = = Q 3
x Nq @ w q @ |= @ "
O
O a '
AJ CtU
O}vm xHwD Q} R |=yOm x@ "Owtv sUQ =Q
{ rnorm(100) y { rnorm(100) plot(x,y, axes=F) axis(side=1, pos=0) axis(side=2, pos=0)
Q
|= @
y x w
2
O
u}}=B
O a '
Q
|= @
1
O
= wLt pLt u=wD|t
| yQ
O
O a " yO
pos
|t u=Wv
= w
wLt sUQ pLt
=Q Q
side
=iDU= =@ "CU=Q CtU |=Q@
u t oQ R= xO
= w
u t oQ
4
O
O a
> < > > > >
<
Q |t XNWt
"OO o
O
x W
XNWt u=mt
QO
3. marginal text
labels at
=yl}D s}qa uDiQo Q=Qk
w
=
= w
| yu t oQ
=@ =yu
|wQ
=y?UJQ@
w
=yl}D s}qa uDiQo Q=Qk pLt
|vWwOv|wUwt
46
An gu l
1
ar t
ex t
2
My title
K
0
some text
−1
c(−2, 2)
KK
−2
K
−2
−1
0
1
2
c(−2, 2) My subtitle
uDt OvJ V}=tv
%172
pmW
K
KK 0
some text
−1
c(−2, 2)
Text in the margin
An g
1
ul ar
te x
t
2
My title
K
−2
1390 '
−2
−1
0
1
c(−2, 2) My subtitle
x}W=L
|wQ
uDt V}=tv
%182
pmW
2
wtv sUQ
47
Q=O
2
My title
1
e
−(x−μ)2 2σ2
0
some text K
−2
−1
K
−2
−1
0
1
2
c(−2, 2) My subtitle
wtv
w Q V}=tv
|wQ p t i
%192
pmW
1
2
Q=O
0
y
−2
−1
0
1
2
−1
−3
−2
c(−2, 2)
K K
Text in the margin
An gu l
1
ar t
ex t
σ 2π
x
=yQwLt pLt Q}}eD V}=tv
%202
pmW
2
pYi
1390 '
> > > >
48
x { rnorm(100) y { rnorm(100) plot(x,y, axes=F) axis(side=1, pos=0) axis(side=2, pos=0) < <
−2.0
−1.2
y
−0.4
0.4
1.2
2.0
>
|vWwOv|wUwt
−2.0000000 −0.8571429
0.2857143
1.4285714
x
wLt
Q
=yl}D s}qa > > > > > > > > s
|wQ
=yl}D pLt V}=tv
%212
pmW
= ?UJQ@ uDiQo Q=Qk
|wQ y
x { 1:20 y { rnorm(20) plot(x,y,axes=F) xtickplaces { 1:20 ytickplaces { seq(-2,2,l=6) xlabels { paste("day", 1:20, sep=" ") axis(side=1, at=xtickplaces, labels=xlabels) axis(side=2, at=ytickplaces) < <
<
<
<
=tD O}y=wN@ Qo = "OvQ}o|t Q=Qk sy "
CU= Q}PBu=mt=
|wQ
cex.axis QD
=yu xm u}=
= =@ Q=m u}=
t=Q B
Q
w |tv
|= @ "O W
xO=O
Q lJwm =yQDm =Q=m
"OO o
V}=tv OwHwt
= ?UJQ@ s=tD
| y
O O}=@ OvwW
xR= v=
xO=O u
x { 1:20 y { rnorm(20) plot(x,y,axes=F) xtickplaces { 1:20 ytickplaces { seq(-2,2,l=6) xlabels { paste("day", 1:20, sep=" ") axis(side=1, at=xtickplaces, labels=xlabels, cex.axis=0.5) axis(side=2, at=ytickplaces) w Q} x C O =iD box() = x |a = =F u O}v x w labels at
>
<
>
<
R
=Wv =yQwLt
=
u @ R QO
|wQ
=yu
> >
<
>
<
<
> > >
u t= B
m
U= x W xO
U=
s v
@
@ D R= p t
}= QO "
m
H D "
w
Ovm|t sUQ
C=Q
wDUO
=iDt p=mW= x@
Cw
Qo}O p=Ft x@
R= |
= pmW
|QO m
wtv sUQ
Q=O
−1.2
−0.4
y
0.4
1.2
49
day 1
day 4
day 7
day 10
day 13
day 16
day 19
x
wLt
|wQ
=y?UJQ@ pLt V}=tv
%222
pmW
0.4 −1.2
−0.4
y
1.2
2.0
Q
day 1
day 3
day 5
day 7
day 9
day 11
day 13
day 15
day 17
day 19
x
lJwm
O =@ QwLt
xR= v=
|wQ
=y?UJQ@ pLt V}=tv
%232
pmW
2
pYi
1390 '
> >
50
plot(1:7, abs(rnorm(7)), type = 'h', axes = FALSE) axis(1, at = 1:7, labels = letters 1:7]) box(lty = 'dotdash')
abs(rnorm(7))
>
|vWwOv|wUwt
a
b
c
d
e
f
g
1:7
Q
w
h L CQ Y
Cr=L "Ovm|t XNWt
=Q
l}D Ctqa
x@ QwLt
|wQ
=y?UJQ@ pLt V}=tv
O QDt=Q=B u}= "CU=
xR= v=
Ovm|t sUQ
"
tck =Q Q=O
wtv
O
%242
=iDU=
xO
pmW w |t xm
u R= u= D
wtv xm@W \N `k=w
QO
Qo}O O}it QDt=Q=B
|
xm CU=
tck=1
x { 1:20 y { rnorm(20) plot(x,y,axes=F) xtickplaces { 1:20 ytickplaces { seq(-2,2,l=6) xlabels { paste("day", 1:20, sep=" ") axis(side=1, at=xtickplaces, labels=xlabels, cex.axis=0.5) axis(side=1, at=c(5,10,15,20,25), labels=rep("",5), tck=1, lty=2) axis(side=2, at=ytickplaces) wL Q O} wN Q wt =iD log="y" = log="x" w | y = x |tD =o = O}v =iD log="xy"
>
<
>
<
O
u | L
> >
<
>
<
>
<
> > > Q
t wO
y
y=
@
o = "O
v xO
U=
}
R= u= D
t
"
} w
m xO
}Q
U=
wLt sUQ
r | yQ
w
R= O W
Q
|= @
|tD} Q=or
wtv sUQ
Q=O
−1.2
−0.4
y
0.4
1.2
51
day 1
day 3
day 5
day 7
day 9
day 11
day 13
day 15
day 17
day 19
x
lJwm
O =@ QwLt
xR= v=
|wQ
=y?UJQ@ pLt V}=tv
%252
pmW
2
pYi
swU pYi
=tD
p
p@=k O=OaD =yu Q@
qa "CU=
xw
O
" W
=
=
=
L= w Q t
O
=
p}rLD
|Q t |R Up t w yxO=O
Oy=wN EL@ =yu
R= |Ow
OLt
OaD
O=
=
=@ =Lt
Q `@=D
'|Q t C U
|wQ
=Hv}=
|= @
w
QO "OQ=O O Hw
=y
=
|O } R O=
package
|Q=t
O = |t
" W @
Q
Q=
u=w= i O @ m |=Q=O
Q} R CUQyi "CU= O=} R Q=}U@
" yO
t =Q
" yO
|t
O
|t
52
=Q
=Q
Y a
R
x_Lqt
|=
13
`@=wD
1 1 3
u @ R QO
`@=wD CUQyi
=
xQ
=v
wtHt
Y a `
D
H
Y a ?
t =Q
" yO
" yO
`@=D
=
u @R
sum(x) | x Q =v |atH `t %cumsum(x) O | x Q =v Q p = %prod(x) O | x Q =v QF O %max(x) O | x Q =v p O %min(x) x QYv u QD R T O %which.max(x) O
" yO
O
QO
x}=B `@=wD
O=} R |Q@ Q=m =@
R
OaD pt=W
t =Q
Y a
" yO
t =Q
Y a
a
oQ @
} v=
}
Y L
m= L
k= L
%
=tDL=
53
p
=
w Q t
3
pYi
which.min(x) C c(min(x), max(x)) =a ` = u %range(x) O | x Q =v Oa %length(x) O | x Q =v u}o =} %mean(x) O | x Q =v x =} %median(x) O | x Q =v T = %var(x) O | x Q =v =}a QL %sd(x) O = T Q = l x Q Ov | x@ =L |oDU@t T Q = %cor(x) O | C O y x u} |] |oDU@t ? Q %cor(x,y) C | x Q | wm w %chisq.test(x) C h Q}t Q wtr x Q | wm w %ks.test(x) C x wt = l Q C wD t w %t.test(x) C y x T= QQ w %var.test(x,y) O
" yO
"
|t
x QYv
=Q
u} QDmJwm T}Ov=
a
U=
pO
" yO
t =Q
} D t
" yO
t
"
"
U=
}
o= '
Y a
" yO
t =Q
Y a
U @
U=
"
U
v wO
U=
v } Q=w
t h=
y
y
}
v=
} D t
}
v u tR
@ VR= @
}
} |= @
w
v t
t =Q
N
}
D
v t
Y a Q
@ VR= @
}=
Y a
t =Q
m VwQ
v
t =Q
@ =Q
N VwQ
U=(hw o
"
t
w
U= wO
v
m
@ D
Y a O=
t =Q
" yO
" W @
t
" yO
" yO
%
v u tR
vO
U=
u tR
v } Q=w | @= @ u tR
|iO=YD O=Oa= w |r=tDL= |=y`} RwD OvDUy Q} R
"
w
CQ Y
x@ xm 'CU=
=iDt pmW Q=yJ
Cw
O
|t u=Wv
" yO
O
|t u=Wv
" yO
O
|t u=Wv
" yO
"
Q@ Q=m
w
CU=
Q V}B
w
Z i
CQ Y
0
x x]k
Ovm|t
x x]k
=D
v
< p <
1
`@=D
v QO =Q
|=R=
= x}@W =Wv
u
Q
x@
=Q
=Q
=Q
`@=D
`@=D R=
l
dfunc(x,
)
pfunc(x,
)
qfunc(p,
)
|iO=YD xvwtv
rfunc(x,
)
'
Q
l} CUQyi
R= | U
O =tv |WQ=iU
" }
O}vm xHwD CU= p=tQv p=tDL= `@=D
|=Q=O
|r=tDL= `@=wD QDW}@
'
OvJ Q=Okt
|r=tDL= `@=wD
"
=
u @ R QO
Z a '
|atHD p=tDL= Q=Okt
=Q
|R U
x@ =yQDt=Q=B xm 'OyO|t
R
`@=D Qy "CU= xOW xDW=Po
|=Q=O
w ?UL
OQ t
xm |iO=YD OOa
2 1 3
w
OQ t QO
wDUO
wDUO
wDUO
wDUO
Q
Q
Q
Q
O
13 pw H QO =Q
=yu Ov=wD|t
Q} R p=Ft x@
rnorm(1) 1] 1.358007 >
Q
| U
Q
= H=
=@ xm
Qy
Q |t O=H}= |iO=YD
'OO o
=ov 'O}vm
QO x
O
OO
=iDU= |iO=YD O=Oa= `@=D
xO
Q
l} O}vm|t =QH=
O= a= R= | } H | U
Q
p@k
|= H= R=
set.seed()
CU= K}LY OOa l} Q}N= `@=D u=twoQ
" "
O}vm xHwD Q} R p=Ft x@ `} RwD l}
w O
"O @ x W
X (x) = Pr(X
F
|iO=YD
=Q
wDUO
Q
R=
O
O= a=
Q_v
w `@=D xm Q=@ Qy
OQ t
Qo = uwvm = "CU=
O}rwD ,q@k xm Ci=} O}y=wN
) |atH
x
D p
=tDL=
=iDt u}W}B
Cw
Q
=ty
CUO@
|= @
=Q | U u
uOQw
Q
1390 '
|vWwOv|wUwt
54
u
`@=wD
=
= ` w
O
w |Q t | y } R D %13 pw H
package beta beta shape1, shape2 -, stat binomial binom size, prob -, stat Cauchy chauchy location, scale 0, 1 stat 2 chisq df, ncp -, 0 stat Dirichlet dirichlet alpha MCMCpack exponential exp rate 1 stat F f df1, df2, ncp -, -, stat gamma gamma shape, rate, scale -, 1, 1/rate stat geometric geom prob stat Generalized Extreme Value gev xi,mu,sigma -, -, evir Generalized Pareto gpd xi,mu,beta -, -, evir hypergeometric hyper m, n, k -, -, stat Inverse Gamma invgamma shape,rate -, MCMCpack Inverse Wishart iwish v, S -, MCMCpack logistic logis location, scale 0, 1 stat lognormal lnorm meanlog, sdlog 0, 1 stat Multinomial multinom size, prob -, stat lognormal lnorm meanlog, sdlog 0, 1 stat Multivariate Normal mvnorm mean,sigma -, mvtnorm Multivariate-t mvt sigma,df -, mvtnorm negative binomial nbinom size, prob, mu -, -, stat nomal norm mean, sd 0,1 stat Poisson pois lambda stat 'Student' (t) t df, ncp -, 0 stat Weibull weibull shape, scale -, 1 stat uniform unif min, max 0,1 stat Wilcoxon wilcoxon m, n -, stat Wishart wish v, S -, MCMCpack C R = w |r xDU = x = w_v ( `} RwD
O)m
=yQDt=Q=B
Q V}B
Z i
"
U=
u @R O N
Y=
y
} w
} B Q
t
=tDL=
55
p
pnorm(1.96) 1] 0.9750021
=
w Q t
3
pYi
>
"OQw
CUO@ R}v
=Q
1
X (x) = Pr(X
)
; F
> x
pnorm(1.96, lower.tail=F) 1] 0.02499790
p
=tDL= |i== u=mt= l} =@
w |t uwvm =
u= D
>
w
u tR
|v=QL@ Q}O=kt |=Q@ ,qFt "OQ}o|t Q=Qk xO=iDU=
w
=
w
OQ t |Q t u tR QO
P-value =
CU= Q} R
w
"
qnorm(0.025) 1] -1.959964 qnorm(0.975) 1] 1.959964
|v=QL@ Q}O=kt uOQw CUO@ |=Q@
} w
CQ Y
x@
&
5
Q
= Q `} RwD xiQ]
|= @ p t v
wO
>
>
= CU= Q@=Q@
% @
1-pchisq(3.84, 1) 1] 0.05004352
df=1 = 2 = 3 84 @
:
w
P-value
Q
u tR |= @
Okt
Q=
>
O}vm
"
1-pf(3.6,4,43) 1] 0.01284459 %5 w Q|
=UL
?
f(4,43) ` =
@ D QO =Q
3.6
O
O a
P-value
Q=
Okt "O}vm xHwD Qo}O p=Ft l} x@
>
u J OO o
t OQ
w
|vat K]U
uO @ Q=O
w
Q
"O W ? wO QO
Q =t= "CU=
|= @
O}=@
P-value
u R=
QDoQR@ =Q} R OwW|tv
w xiQ]
O @
w
wO u tR
%
OQ
Qo = xm OwWv
1
w
|vat K]U
uO @ Q=O
w Q CU=
V t= i "
u R=
Q
|= @
QDmJwm
1-pt(2.8,21) 1] 0.005364828 2 (1-pt(2.8,21)) 1] 0.01072966 >
>
O}vm x@U=Lt
"
=
=Q u | yl
OvJ O}v=wD|t O}W=@ xDW=O
w
=Q uO @ Q=O
|vat K]U Qo = uwvm =
alpha - c(0.1, 0.05, 0.01, 0.001) qnorm(1-alpha/2) 1] 1.644854 1.959964 2.575829 3.290527 >
<
>
s=QowDU}y
CU= Q} R KQW x@
%
u
Qt=Qo xm "CU= |iwQat
Q=O
wtv
Q wDU}y p=tDL=
's= o
hist(x,breaks="Sturges",prob=FALSE) =H}=
O
=Q
|@U=vt=v pmW Ov=wD|t sm |r}N =} O=} R |r}N =yxDUO "
CU= Q} R pmW x@
u
x]@=Q xm Ovm|t
xO
=iDU=
OaD "OyO|t u=Wv
O=
Sturges
log2 ( ) + 1
d
n
e
w Q
p t i R=
R
=Q
=yxDUO =
1 2 1 3
O=
OaD
breaks
Q V}B
u @R Z i
w
=
w Q t QO
= w
u t oQ
Ovm
CQ Y QO "
1390 '
=
T U=
|vWwOv|wUwt
Q@ xm
56
Freedman-Diaconis (FD)
w Q pFt 'Ovm|t u}at =Q xDUO |=vyB xm OQ=O OwHw R}v |Qo}O |=yVwQ
p t i
CU= Q} R pmW x@
"
2 iqr
CU= xOW O=yvW}B
"
Scott \ 35 :
x]@=Q
u
=F
wvax@ "O}vm
=iDU=
xO
w
U D w
CU= Q} R pwtQi
nclass=num. of class Q |t s}_vD
OO o
x w x pmW
|= v o @
=v@t xm
u |
w
= w
CU= Q=}at
O}v=wD|t OW=@ =tW Q=}DN=
u t oQ R=
20 Q_
|
Qo}O pwtQi
w
w |t p=aiQ}e |v=w=Qi
w O W
w |t u=}@ Q} R
%O W
QLv=
h=
q =
s u QO
xm
QDvm O}y=wN@ Qo =
QO , t m p
nclass=20 freq=F wD
Q wDU}y
v OQ t s= o
prob=T =
p=tQv p=tDL=
"
OLt
; 31
} w
w
(
R}v
OQ=O O Hw
"O W
f x
xOw
s n
Ovm|t O=H}= xDUO
=yCL=Ut `wtHt xm
|mQ=J u}@
; 31
" QO
n
" p t u=
iqr
Q
"OQ=O Q= k
Q
|= @
Q
OL=w Q@=Q@ s=QowDU}y
|r=oJ `@=D
w x
UO QO
= Q
CQ Y @ p t v p
2 2 1 3
=tDL= |r=oJ `@=D
(x;)2 ) = 1 ; 22 2 p
e
O}vm xHwD Q} R pmW x@
u
|atHD `@=D
=tDL= |r=oJ `@=D V}=tv
w p
Q
|= @
X { seq(-4,4,0.1) par(mfrow=c(1,2)) plot(X,dnorm(X),type='l',xlab="x", ylab="f(x)", main="PDF's Normal") plot(X,pnorm(X),type='l',xlab="x", ylab="F(x)", main="CDF's Normal") <
wtv
w O
= x}@W
|R U
w Pt `@=D
=Q Q m
= Q |iO=YD
'p t v
O
O= a=
=@
w |t uwvm =
u= D
Q |t pY=L Q} R pmW
"OO o
Q xU}=kt
"O m
set.seed(5) Y { rnorm(2000) # 2000 from Normal(mu = 0, sigma=1) <
O w |t
" v W
P
h L
4
R=
QDoQR@
w
-4
R=
QDmJwm
Y Y -4 | Y 4] { NA x { seq(-4, 4, .1) <
>
O
O= a=
Q} R QwDUO
QO
<
<
"O
wtv sUQ pmW l}
QO =Q
|r=oJ `@=D
Q wDU}y
w s= o
u=
wD@ =D OwW|t p=aiQ}e |v=w=Qi Q} R QwDUO
QO
hist(Y, breaks="FD", xlim=c(-4,4), freq=FALSE, main="") title("Histogram of Normal distribution") lines(x, dnorm(x), lwd=2)
=
= O
Q
'q @ | y ) m |= H=
Q_v `@=D =@
|
=@
=Q u
=tDL=
57
p
CDF’s Normal
F(x)
0.0
0.0
0.2
0.1
0.4
0.2
f(x)
0.6
0.3
0.8
1.0
0.4
PDF’s Normal
−4
−2
0
2
4
−4
−2
x
= Q |atHD
p t v
w p
0
2
4
x
=tDL= |r=oJ `@=D
=
wtv V}=tv
| yQ=O
%13
pmW
0.2 0.0
0.1
Density
0.3
0.4
Histogram of Normal distribution
−4
−2
0
2
4
Y
|
Q_v p=tDL= `@=D
Q wDU}y
w s= o
=
wtv V}=tv
| yQ=O
%23
pmW
=
w Q t
3
pYi
1390 '
|vWwOv|wUwt
58
qqplot() w qqline() 'qqnorm() |m}i=Qo `@=wD =Q "
CU=Q \N l} x=ov 'OvW=@ p=tQv =yxO=O Qo =
qqnorm() ` = = p = qqline() ` =
=Wv
"O=O u
O}vm xHwD Q} R p=Ft x@ "OwQ|t Q=mx@ xU}=kt |=Q@ xm OwW|t
@ D
Q
@ =Q xO=O | U
Y L
@ D R=
l}
3 2 1 3
w
= Q
w |t
uO @ p t v u= D
CU=Q \N s}UQD "OvyO|t V}=tv
x { runif(200) y { rnorm(200) par(mfrow=c(2,1)) qqnorm(x,main="") title("Q-Q for uniform Dis.") qqline(x, col="red") qqnorm(y, main="") title("Q-Q for normal Dis.") qqline(y, col="red") <
<
0.8 0.4 0.0
Sample Quantiles
Q−Q for uniform Dis.
−3
−2
−1
0
1
2
3
2
3
Theoretical Quantiles
2 1 −1 0 −3
Sample Quantiles
Q−Q for normal Dis.
−3
−2
−1
0
1
Theoretical Quantiles
= Q
p t v w
u}= s=Hv=
|= @ # v=x W
=ov 'OvyO@
x
pw=
Q O O
CN=wvm} p=tDL= |r=oJ `@=D
=Q
`} RwD l}
CU=Q \N l} p}mWD
`@ Q R=Ut}v \N u}=
wtv
"O
xO
Q
R= | U wO
=
u}= =} xm Owtv KQ]t
=kv Qo =
\
= Q
OvJ
wO p t v | yl
wtv sUQ =@
Q=O
=iDU= CU=Q \N l}
w
=Q p= U
w
=
"OQ=O O Hw
u}=
x { rnorm(500) y { rnorm(500) qqplot(x,y) abline(0,1, col="blue", lwd=2) <
<
pmW
w |t 'O}W=@ xDW=O w
CQ Y
Q CU= pw@k p@=k
abline(0,1) ` =
l
Q
Qo =
=
=
xO=O | U wO
x@ |a@=D
|= @ "
Q |t pY=L
"OO o
%33
u= D
qqplot()
w |t R}v xU}=kt
R= u= D
wtv V}=tv
| yQ=O
R
u @ R QO Q m
QDWt `} RwD
@ D R= xO
Q
Z i
=iDU= =@ xm CU=
=tDL=
p
=
w Q t
3
pYi
y
−3
−2
−1
0
1
2
3
59
−2
−1
0
1
2
x
Q
=
xO=O | U wO | yl
OvJ
wtv V}=tv
Q=O
%43
pmW
ecdf() `@=D ecdf() x
O}t=v
x
w
m OQ=O O Hw
|a@=D =t=
Q s}UQD
"O m
"
=Q
|atHD `} RwD `@=D
w |t "OW x_Lqt ,q@k xm Qw]v=ty
u= D
O}vm xHwD Q} R p=Ft x@ "OyO|t CUO@
=Q
|@ QHD |atHD `} RwD
w |t
w O W
x { rnorm(10) plot(ecdf(x)) <
CU= Q} R
"
w
CQ Y
x@ pmW 's}UQD
R=
TB
0.6
0.8
1.0
ecdf(x)
0.4 0.2 0.0
>
x@U=Lt
Fn(x)
>
w
4 2 1 3
−1.0
−0.5
0.0
0.5
x
|@ QHD |atHD `} RwD O
|t u=Wv
" yO
Q_v
|
w
|@ QHD Cr=L
QO =Q p
Q=O
wtv V}=tv
%53
pmW
w@} w |atHD p=tDL= `} RwD xm O}vm xHwD
wtv
63 Q=O
w
=yO)m x@ uwvm =
1390 '
> > > >
|vWwOv|wUwt
60
x { seq(0,2,0.1) plot(x, pweibull(x,scale=1,shape=2),type="l", main="ECDF and Weibull CDF") x.teo { rweibull(n=200,shape=2, scale=1) plot(ecdf(x.teo), add=TRUE) <
<
0.8 0.6 0.4 0.2 0.0
pweibull(x, scale = 1, shape = 2)
1.0
ECDF and Weibull CDF
0.0
0.5
1.0
1.5
2.0
x
|@ QHD |atHD `} RwD
Q=O
wtv V}=tv
%63
pmW
=t=o p=tDL= |r=oJ `@=D w
"O W
;( ) =
h}aD =t=o `@=D xm CU=
Z1
;1 e;x dx
x
OD@=
sRq =
>
0 wtv u=}@ Q} R
"O
w
CQ Y
8 > < ;(1 ) ;1 ; x ( )=> :0 x
e
x@
O =
=1
Q=
Okt Qo =
w |t xO}t=v
"O W
scale
=}kt QDt=Q=B
T
=tDL= |r=oJ `@=D u}= u=}@
'p
R=
p@k
0 =Q
x
f x
' W @
5 2 1 3
x <
=t=o p=tDL= |r=oJ `@=D
w |t TBU
u= D
0 0
shape pm
w
W
QDt=Q=B
QDt=Q=B
wO |=Q=O
`@=D u}=
w |t p}O@D |}=tv `} RwD x@ `@=D u}=
"O W "
= 2 X=
X
CU= Q} R
2
w
CQ Y
x@ p=tDL= |r=oJ `@=D u}=
=
| yQw
=DWo
=tDL=
61
=
p
O |t CUO@ Q} R \@=wQ
" }
=
=
w Q t
w
3
j i CqO
pYi
=at pL
R=
2
X X
2 X X
"
O}vm xHwD `} RwD u}=
w
OQ t QO
R
=
=F x@ uwvm =
=
=F x@ uwvm =
| yp t
x { seq(0,10, length=100) par(mfrow=c(2,2)) plot(x,dgamma(x,shape=1,scale=1), type='l',xlab="x", ylab="Prob", main="Shape 1") plot(x,dgamma(x,shape=2,scale=1), type='l',xlab="x", ylab="Prob", main="Shape 2") plot(x,dgamma(x,shape=5,scale=1), type='l',xlab="x", ylab="Prob", main="Shape 5") plot(x,dgamma(x,shape=10,scale=1), type='l',xlab="x", ylab="Prob", main="Shape 10") <
Shape 2
0.1 0.0
0.0
2
4
6
8
10
0
2
6 x
Shape 5
Shape 10
10
8
10
0.12
8
Prob
0.04
0.08
0.15 0.10
0.00
0.05 0.00 0
2
4
6
8
10
0
2
x
hrDNt
4
x
0.20
0
Prob
0.2
Prob
0.6 0.4 0.2
Prob
0.8
0.3
1.0
Shape 1
=
6 x
shape =
| y
4
@
=t=o `} RwD
=
wtv V}=tv
| yQ=O
%73
pmW
O}vm xHwD
"
x { seq(0,30,length=100) plot(x,dgamma(x,shape=2,scale=1), type='l', xlab="x", ylab="f(x)", main="Gamma pdf's") lines(x,dgamma(x,shape=2,scale=2), lty=2) lines(x,dgamma(x,shape=2,scale=4), lty=3) lines(x,dgamma(x,shape=2,scale=8), lty=4) legend(x=20,y=.35,paste("Scale=",c(1,2,4,8)), lty=1:4) <
scale QD
t=Q B p t
1390 '
|vWwOv|wUwt
62
Gamma pdf’s
0.2 0.0
0.1
f(x)
0.3
Scale= 1 Scale= 2 Scale= 4 Scale= 8
0
5
10
15
20
25
30
x
hrDNt
=
scale =
| y
=t=o `} RwD
@
O}vm xHwD Q} R p=Ft x@
"
=
wtv V}=tv
Q
=t=o `} RwD 'Q_v
| yQ=O
"O=O VR= @ =Q
%83
pmW
w
=
Q
l} Q@
w
= O
OQ t | yxO=O | U
w |t
u= D
X { c(4.75, 3.4, 1.8, 2.9, 2.2, 2.4, 5.8, 2.6, 2.4, 5.25) n { length(X) alpha { (mean(X)/sd(X))^2 theta { var(X)/mean(X) x { seq(0, 8, length=200) plot(x, dgamma(x,shape=alpha,scale=theta), type='l', ylab="f(x)") points(X, rep(0,n)) <
<
<
<
<
uO=O u
=Wv
wLv xm
|x
=iD u}= =@ Owtv Q=QmD
Cw
=
=F
w |t xD@r=
w |t pY=L Q} R pmW
=Q q @ p t u= D
O =
wLt
" W @ |Q
"O W
= l}D
| y
w
CQ Y
Q
j i | y ) m |= H=
x@ p@k p=Ft |@ QHD
=@
=
| yxO=O
X { c(4.75, 3.4, 1.8, 2.9, 2.2, 2.4, 5.8, 2.6, 2.4, 5.25) n { length(X) alpha { (mean(X)/sd(X))^2 theta { var(X)/mean(X) x { seq(0, 8, length=200) plot(x, dgamma(x,shape=alpha,scale=theta), type='l', ylab="f(x)") rug(X, ticksize = 0.03, side = 1, lwd = 2) <
<
<
<
<
w |t pY=L Q} R pmW
"O W
w
= O
|iO=YD |Q}oxvwtv =
u @R
\UwD u=wD|t =Q xU}m l} R=
w xU uO}Wm
A D
w
100 = 1 D
"
O
R= O= a=
CU= Q} R |rm
|iO=YD ?=NDv= Ovv=t |r=tDL= w
CQ Y
x@
sample() ` =
Q
j i | y ) m |= H=
@ D "O
=
=@
3 1 3
= x QHD
xO U | y @
wtv
= x}@W
|R U
R
=tDL=
p
0.25 0.20 f(x)
0.15 0.10 0.05 0.00 0
2
4
6
8
x
Q
l} Q@ =t=o `@=D
0
2
Q V}=tv
VR= @
%93
pmW
f(x)
0.00
0.05
0.10
0.15
0.20
0.25
0.30
xO=O | U
4
6
8
x
l}D
w
CQ Y
x@ |@ QHD
\
=kv
Q
xO=O | U
l} Q@ =t=o `@=D
Q V}=tv
VR= @
%103
=
w Q t
0.30
63
pmW
3
pYi
1390 '
|vWwOv|wUwt
64
sample(x, size, replace = FALSE, prob = NULL) 'u QO
O = QDm =Q=m =}
" W @
O Ov=wD|t xm CU= Q_v Q
=NDv= O}=@ xm
"OO o ?
Q
=Hv=
"OO o s
O O
" y @ uRw
Po}=H =@ =}
|Q=
=yxvwtv
w
w O a
w |Q=
Po}=H
O
=NDv= x@ Ov=wD|t xm CU=
x Oa size replace Q prob Q
OQ t Q=O @ % |O=
Q}oxvwtv
uw @ |
?
xm
=}DN=
|Q
D %
%
Q=O @ %
%=yp=Ft
100 = 1
=YD x@ OOa l}
D
R= hO
sample(1:100, 1) 1] 19
?
=NDv=
>
= l} Q=@
10
= l} Q=@
10
T D
sample(1:6, 10, replace = T) 1] 5 4 3 5 4 6 1 5 2 4
=Q
? D B
>
=Ut=v
|w
sample(1:6, 10, c(0.6,0.4,0.1,0.05,0.03,0.02), replace = T) 1] 4 2 1 1 1 2 1 1 4 3 O}v =ND Po = O =Y x Qy 6 wv w Qy 3
=tDL= =@
Cq
T D
=Q
? D B
>
"
m ?
v= |Q=
} H uw @ w hO
D
@ x
t
u
m = "OQ=O O Hw OQR x
t
w
|@ xQyt
4
R Q
' t k x
Qyt
8
xU}m
|=
QO
urn { c(rep("red", 8), rep("blue", 4), rep("yellow", 3)) sample(urn, 6, replace = F) 1] "red" "yellow" "blue" "red" "red" "red"
>
<
>
p=tDL= VwQ
Ovv=t |}=yVwQ
R= "O
wtv
Q
=tDL= `@=D l}
OQw @ =Q p
wtv
"O
Q |}=tvDUQO QFm =OL
OQw @
VwQ
x@
=Q p
=tDL= `@=D
=
xQ W=
= QDt=Q=B xm
| y
CU= Q=Qk xm |}=yxO=O pw= 'CU= |QwQ u=twoQ
wO |=Q=O
Q}o Q=Qk uW}Dwm pN=O
"O
`@=D
Q =@ uwvm =
Z i
w |t O}rwD XNWt
"O W
Q |t
"OO o
Q CU=xDi=}
OQw @ '
<
<
<
<
1. Maximum Likelihood
u= D
Q
MASS wv w tdistr()
w
O}=@ xm Q_v
u=
t
w
Q w Pt
VR= @ Q m
=
| yxO=O
CLD
VwQ w
xDU@
|=
R
=yQw=DWo
=
u @ R QO
= x@ |a@=D xDU@ u}= QO "Ovm|t
s v
=tDL= `@=D
OQ t p
= QDt=Q=B =@ =t=o `} RwD =@ |iO=YD
| y
a
4 1 3
x@ O}v=O|t xm Qw]u=ty
w |t 1 |}=tvDUQO QFm =OL
=
xm CU= OwH
QO
=
| yVwQ
w O @ s v u= D
OQ=O O Hw
library("MASS") set.seed(1) random { rgamma(500,8.5,2.5) para { tdistr(random,"gamma") print(para) para { unlist(para) x { seq(1,10,0.1) y { dgamma(x,8.5,2.5) <
w |t hrDNt
= QDt=Q=B
| y
=yv x@
`@=D l} |=yQDt=Q=B OQwQ@
O
swO w
Q
O= a= | U
Q@ xm =t=o p=tDL= `@=D
O@=}
Q |a@=D =yv Q@
VR= @
l} =OD@= =Hv}=
QO
%p=Ft
= QDt=Q=B ,=OOHt =t=o p=tDL=
| y
=tDL=
65
=
p
w Q t
pYi
3
plot(x,y,type="l") lines(x,dgamma(x,para 1],para 2]),lty=2) legend(7.0,0.30,legend=c("exact", "ML"), lty=c(1,2), bg="gray90") w |t pY=L
0.3
"O W
113
pmW q=@ xt=vQ@
Q
|= H=
=@
0.0
0.1
y
0.2
exact ML
2
4
6
8
10
x
O
Q
= QDt=Q=B =@
x W OQw @ | y
Q
xO=O | U
l} Q@ =t=o `@=D
Q V}=tv
%113
VR= @
pmW
|Q=t |=yVwQ
Q |t O}m =D =yu u} QDQwyWt
"OO o
|wQ
=Hv}=
QO "
CU=
Q
w
=
=
5 1 3
t xiQ] wO w l} uwtR p
L=
r
J
@ D
@
}= QO
yZ i "
U=
u tR ` v
Q |rY= `@=D
}= |= @
%u QO
CU= OwHwt
" w
"greater" "two.sided" '
Q V}B
u Z i
Qo = 'Ovm|t u=}@
wO
=Q
w
l} x=ov
Q |t u=}@ =yQDm =Q=m
O}vm
xO
=iDU=
=yu}ov=}t
h
|
wWv
'O
xO=O
yQ
o= "
OvDUy
R= |=
Q}oQ=mx@
Q R}v
|= @
qDN= =} OyO|t u=Wv
Q
u pw= hw L R= =Q
u}ov=}t CUQO "
O
=
Q
|O a | yQ=O @ % Z i % v= D
Q=
t
t
CU= QiY Q@=Q@
W "
m |O a %
Q V}B "OW=@
Z i
paired var.equal conf.level
O}W=@ xDW=O |}=DwO uwtR O}y=wN@ Qo = CU= |k]vt xv=Wv
"
CU=
"
F
Q V}B
u Z i
u} Ro}=H
w
OvQ@=Q@ sy =@ =yTv=} Q=w OW=@
Q ?UL Q@ u}ov=}t
Z i
xrY=i
|=
"
Q
T
CUQO Qo = "CU= |k]vt Q}eDt
95 mu=70 Qi Q
OQw @ |= @ &
O}vm uwtR
=Q
Q V}B u=v}t]= K]U
Z i
Q
Y Z i
xm
x,y Q alternative O} w | =t "less" Ok x O mu
xDWQ \UwD u} Ro}=H
"OO o "
xDW=O OwHw xvwtv
=
xO U u tR
=
u @R
1 5 1 3
t =tD | =o ` = = =Hv = Q C t.test() w w u t.test(x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, var.equal = FALSE, conf.level = 0.95) w |t uwtR
"O W
R
= R}t
Z i u tR w |Q t | yVwQ u @
trees
=
%
% %
| yxO=O QO
%1 p=Ft
1390 '
> >
|vWwOv|wUwt
66
data(trees) t.test(trees$Height, mu = 70) One Sample t-test
data: trees$Height t = 5.2429, df = 30, p-value = 1.173e-05 alternative hypothesis: true mean is not equal to 70 95 percent condence interval: 73.6628 78.3372 sample estimates: mean of x 76 w |t
"O W
xDU=m =yu p}=t
h
QYt
mpg Q}eD
t "
R=
=} xm CU= u}=
Ovm|tv
xO
=iDU=
w
p= U u
u R=
Qo}O
wvm =
Q |t xi==
"OO o
w
|wQO N
w
wQO N
VW w Ovm|t "
OQ
QiY
CNwU x@ |vOwRi= l} O}vm
=iDU=
xO
CU= Q} R
w
u R= wQO N
w x xm 'CU= xOW
Q
%2 p=Ft
Q
w |t
Z i
VW Q=m u}=
CQ Y @
Q u}=Q@=v@
Z i
|= @ #O W
Q}oxR=Ov= ur=o Q@
|
1 2 3 4 5 6 Car mpg w/ additive 24.6 18.9 27.3 25.2 22.0 30.9 mpg w/o additive 23.8 17.7 26.6 25.1 21.6 29.6 > > >
add { c(24.6, 18.9, 27.3, 25.2, 22.0, 30.9) noadd { c(23.8, 17.7, 26.6, 25.1, 21.6, 29.6) t.test(add, noadd, paired=T, alt = "greater") <
<
Paired t-test data: add and noadd t = 3.9994, df = 5, p-value = 0.005165 alternative hypothesis: true dierence in means is greater than 0 95 percent condence interval: 0.3721225 Inf sample estimates: mean of the dierences 0.75 w ks.test ` = "O tR
> > >
x { runif(100) out { ks.test(x, "pnorm") out <
<
One-sample Kolmogorov-Smirnov test data: x
@ D
=@
Q
=Q |Q=O @ |xO=O
l}
w |t
u= D
=tDL=
67
p
D = 0.5007, p-value 2.2e-16 alternative hypothesis: two-sided wt =iD k-s
=
w Q t
3
pYi
<
"O
> > >
v xO
U=
w
w |t R}v OvW=@ xOW PN= `} RwD l}
u tR R= u= D
Q
R= |Q=O @ |xO=O wO
Qo =
x1 { rnorm(100) x2 { rnorm(100) ks.test(x1, x2) < <
Two-sample Kolmogorov-Smirnov test data: x1 and x2 D = 0.08, p-value = 0.9062 alternative hypothesis: two-sided Q p = Q G =D w = Q = 300
"OO o
Y L
}R
} v w O W ? D B Q @
= xHw
T D
|v=w=Qi `@ Qt uwtR
= u}=
R= Q m
Q CU=
|= @ #
1 6
= l} xm O}vm
T D
Q O}}=tQi xHwD |N `@ Qt uwtR
Z i "
1 2 3 4 5 6 43 49 56 45 66 41
= xHw Qy uOt p=tDL= |va} "CU=
T D
Q |@
h ]
= u}= xm CU= u}=
O}vm xHwD Q} R
> >
w
T D
"
>
=F l} x@ uwvm =
R= p t
= O x@
| y ) m
w |t
"O W
p= U u
wvm =
=iDU= |N
xO
counts { c(43, 49, 56, 45, 66, 41) probs { rep(1/6, 6) chisq.test(counts, p = probs) <
<
Chi-squared test for given probabilities data: counts X-squared = 8.96, df = 5, p-value = 0.1107 w |t
"O W
w
Q |@
OQ uO @ h ]
Q u}=Q@=v@ "CU=
Z i
1 6
>
0 1107 x :
w |t x_Lqt
m O W
sQ=yJ pYi
u
lm, pF
t
w} Q
= O
U oQ | yp t
|a@=wD uOv=wN=Qi j} Q] R= =ypOt u}= ,=twta "CU= |Q=t |=ypOt "
CU= Q} R
w
CQ Y
x@
Q
=
Q
Q
=
R glm,
= u}DwQ |=Q=O
VR= @ |= @ |O } R | y
O l} |rm pmW "Ovvm|t pta
VR= @ |Q t p t
=
u @R
respose ~ expression uw}UQoQ |=ypOt
|]N
pwtQi |=yC}OwHwt
O
" yO
y
`} RwD
=@ =
|=Q=O , r e "
= 0+ 1 1+
|va} =]N xrtH "OyO|t u=Wv wtv
"O
x
=Q u
+
Q Q} R
VR= @
w
y ~ x1+x2 68
w
CQ Y
x@
=Q
|]N pOt l}
1 1 4
R
=
u @R
p p+"
x
w}UQoQ ?}=Q
=iDU= Q} R pwtQi
xO
|t
14
lm() ` =
O@t
w <=
2 "CU=
@ D R= xO
Q
R= Z a
=( 0 1
p ) xm
" Tv=} Q=w w QiY u}ov=}t =@ p=tQv
=iDU= =@
w |t 'Q}eDt
u= D
wO
=@ uw}UQoQ
Q
|= @
w}UQoQ
69
u
CU=
"
P
h L <=
O@t
Q O}U} wv@ Q} R
R= Z a
w
x@
CQ Y
= 0+ 1 1+ 2 2+
y
w x]@=Q =t=
=Q j i
x
w |t <=O@t
O
w Q xrRvt x@
x
"O W
=
| yp t
w
" p t i
Q pt=W
R= Z a
R
pYi
4
=@ xm
j i CQ a
=
Q V}B Qw] x@
u @ R 'Z i
Q |t
"OO o
y ~ -1+x1+x2 xHwD Q} R
=F x@ "OvDUy |]N uw}UQoQ
=
| yp t
QO
|Y=N |v=at
= Qorta xm O}W=@ xDW=O xHwD
*,-,^,\,:
|=Q=O
| y
O}vm
"
y ~ x1+x2+x1:x2 "
CU=
y
= 0 + 1 1 + 2 2 + 12 1 2 +
"
x
x
Ovm|t O=H}= ?}DQD x@
=Q
w Q xrRvt x@
x x
|} wOwO
w
w
" p t i
xv=o}
=@ xm
j i CQ a
= xrtH ^ Qorta
| y
=iDU=
R= xO
y ~ (x1+x2+x1:x2)^2 CU= Q} R x]@=Q
"
y ~ x1+x2+x3+x1:x2+x2:x3+x1:x3 P O@ Q -1 O x_ q q@ x w h L =Q <=
t R= Z a
W
L
t,
k
=at q=@ pwtQi
pO
=ty "Ovm|t hPL uw}UQoQ xrO=at R= =Q |DqtH =} w xrtH - Qorta
m Q ]u
O}vm xHwD Q} R p=Ft x@
"
"O
wtv
y ~ (x1+x2+x1:x2)^2 - x2:x3 "
CU= Q} R x]@=Q
=at q=@ pwtQi
pO
y ~ x1+x2+x3+x1:x2+x1:x3 O}vm xHwD Q} R p=Ft x@ "Ovm|t Q=QmD Q}eDt
"
y ~ I(x1+x2) qFt "Ovm Q}}eD pOt
,
QO
x2 Q}eD
t
O}y=wN@ Qo = ,=vt "CU=
y
= 0 + ( 1 + 2) +
O
Q
x
x
=@DW= O}vm pta Q} R
" }=xO m x
Q
|= @ =Q
w Q xrRvt x@ jwi
w
x@ Qo =
w
@ D
=@ xm
" p t i
CQ Y
I `=
|@} Q
CQ a
Q
"O W ? wO QO
y ~ x1+2*x2 wtv pta O}=@ Q} R
"O
y ~ x1+I(2*x2) "
R
CU= Q} R KQW x@
=
w Q
=ov 'OW=@
u @ R QO u p t i x
y
w
CQ Y
= 0+ 1 + 2 2
x
x
x@ ?r]t uOW CUQO
w x Q_v
CQ Y @
w
Q
|= @
O Qo =
OQ t p t
y ~ poly(x, 2) Q
w x xv
% } R CQ Y @
w
y ~ x+x2^2 |R=UpOt
p}rLD
Q
w VR= @ |=
q@
=
|O } R
CU= Q} R KQW x@ =yu
"
`@=wD =
"OQ=O
= w
=yQ}eDt u}@ |]N \@=wQ = xm CU=
| yu t oQQ R= |=xQ B
lm()
=}
`@=wD
Q |a}Uw OQ@ Q=m |]N
u @ |= @
= u}=
Q m
Q |rY= `@=D
|= @
w}UQoQ
2 1 4
=
O
u
| yp t
"OQ=O O Hw
|]N uw}UQoQ
w
1390 '
|vWwOv|wUwt
70
lm(formula, data, weights, subset, na.action) O}vm xHwD Q} R
"
=
| yxO=O
x@
gene1 gene2 -1.06 -1.08 -0.81 -1.02 -0.48 -0.39 -0.42 -0.48 -0.30 -0.58 -0.35 -0.24 -0.31 -0.05 -0.18 -0.33 -0.20 0.51 -0.11 -0.53 -0.09 -0.47 0.16 0.10 0.45 0.39 0.53 0.11 0.67 0.52 0.80 0.34 0.87 1.08 0.92 1.21 =Q u
x@
w Q
w
\ @ t u tR w
|oDU@ty ?} Q =OD@= xm "CU= xOW xQ}NP Ovm|t |UQQ@
"
> >
=Q
=yu x@
w Q
w
gen_reg.txt O w
\ @ t OQ= t x v= N =Q u
x - read.table("F:/R_les/data/gen_reg.txt",header=T) cor.test(x$gene1, x$gene2) <
Pearson's product-moment correlation data: x$gene1 and x$gene2 t = 7.5105, df = 16, p-value = 1.246e-06 alternative hypothesis: true correlation is not equal to 0 95 percent condence interval: 0.7071560 0.9556856 sample estimates: cor 0.8826268
Q} R
= x@ |r}=i
s v
= O
| y ) m "O
w
=
QO j i | yxO=O
wtv O}y=wN x_Lqt
w}UQoQ
71
=
u
O
| yp t
4
pYi
Q} R pwtQi =@ uw}UQoQ pOt uwvm =
gene2 = 0 + 1 gene1 +
"
Q |t p=ta= =yxO=O
"OO o
> > >
|wQ
x { read.table("F:/R_les/data/gen_reg.txt", header=T) m.reg { lm(gene2~gene1, data=x) m.reg <
<
Call: lm(formula = gene2 ~ gene1, data = x) Coecients: (Intercept) gene1 -0.05541 0.97070 "
> >
CWwv R}v sy Q} R
w x
w |t
=
= O
=Q q @ | y ) m
CQ Y @ u= D
x { read.table("F:/R_les/data/gen_reg.txt", header=T) m.reg { lm(x$gene2~x$gene1) m.reg <
<
>
Call: lm(formula = x$gene2 ~ x$gene1) Coecients: (Intercept) gene1 -0.05541 0.97070 "
O}vm xHwD Q} R
Expression coef(obj) resid(obj) tted(obj) summary(obj) predict(obj,newdata=ndat) deviance(obj)
O
pw H
O}Wm
> >
xDi=}
U=
Q \N
VR= @
u
wtv sUQ
w O
= |HwQN uDi=}
y
=Q
w_vt
R= Q
Vvm =QB
wtv
Q=O
w
Q
|= @
=F
j i p t QO
w |t uwvm =
u= D
plot(x$gene1, x$gene2) lines(x$gene1, tted(m.reg)) wtv
"O
>
=Q
w Q
\ @ t | y
Description regression coecients residuals tted values analysis summary predict for new data residual sum of squares C m.reg =t obj "
"
x@ uw}UQoQ x@
xO
=iDU= R}v Q} R
wDUO
C=Q
w |t xDi=}
R= u= D
plot(x$gene1, x$gene2)
Q \N sUQ
VR= @
Q
w |t pY=L Q} R pmW Q} R
|= @ "O W
= O
Q
) |= H= | y m
=@
|vWwOv|wUwt
72
0.0 −1.0
−0.5
x$gene2
0.5
1.0
1390 '
−1.0
−0.5
0.0
0.5
x$gene1
xDi=}
>
wtv sUQ
>
Vv+m =QB
wtv l} V}=tv
Q=O
%14
pmW
w |t R}v
u= D
= O =t}k=@ 'xDi=}
=Q yx v
Q \N w |@ QHD \=kv Q@
VR= @
xw
qa xm O}vm|t x_Lqt
=Q
|rmW Q} R
QO u
wvm =
plot(x$gene1, x$gene2) lines(x$gene1, tted(m.reg)) segments(x$gene1, tted(m.reg), x$gene1, x$gene2, lty=2)
0.0 −1.0
−0.5
x$gene2
0.5
1.0
>
w
abline(m.reg)
"O
>
Q \N
VR= @
−1.0
−0.5
0.0
0.5
x$gene1
=yxOv=t}k=@ O =D
=]N
w OQ= v U= |
tQ
'
=kt Q}_v xDi=}
}O
Q
w}UQoQ
w u
O
VR= @ p t R=
wtv l} V}=tv
Q=O
|i==
= q]=
C a
%24
=
pmW
R= |=xQ B uOQw
CUO@
Q
|= @
summary() ` =
@ D
O}vm xHwD Q} R p=Ft x@ "CU= O}it =yQDt=Q=B u}@ |oDU@ty
"
>
summary(m.reg)
w}UQoQ
73
u
=
O
| yp t
pYi
4
Call: lm(formula = x$gene2 ~ x$gene1) Residuals: Min 1Q Median 3Q Max -0.3812 -0.2196 -0.0084 0.1492 0.7595 Coecients: Estimate Std. Error t value Pr( t ) (Intercept) -0.05541 0.07330 -0.756 0.461 x$gene1 0.97070 0.12925 7.511 1.25e-06 *** | Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 >j j
Residual standard error: 0.311 on 16 degrees of freedom Multiple R-squared: 0.779, Adjusted R-squared: 0.7652 F-statistic: 56.41 on 1 and 16 DF, p-value: 1.246e-06 wtv x@U=Lt
"O
w}UQoQ xrO=at ?}=Q
=Q u
coef(m.reg) (Intercept) gene1 -0.05540906 0.97070027 connt(m.reg) 2.5% 97.5% (Intercept) -0.2107882 0.09997012 gene1 0.6967126 1.24468796 C Q Qy w | predict.lm() ` = = u Q
xrY=i
|=
Q
w |t
OQw @ u= D
connt() ` =
@ D
=@
>
>
"
i o x
@ u= D
t
@ D R= Q m
"O=O
}= |= @ "O
CUO@
wtv OQwQ@ uw}UQoQ xrO=at R= xO=iDU= =@ =Q |O}OH Q}O=kt u=wD|t
=Q |=
xrY=i
Q sy
OQw @
x]kv
w |=
Q
Okt sy
OQw @ Q=
w
CQ Y
u}=
predict.lm(m.reg, newdata=data.frame(gene1=c(0.1,0.2)), int="conf") t lwr upr 1 0.04166097 -0.11587731 0.1991993 2 0.13873100 -0.02557153 0.3030335 C O O O =W = x =t x =y xr = Q x]k = y =t =o wW =iD newdata
QO
>
U @ x W x y
t | y
s
D |=R=
@
v |=
Y i OQw @ w |=
v | y
s
D x
v 'O
v xO
U=
R=
Qo =
O |t
" }
wtv pta R}v Q} R
"O
predict(m.reg, list(gene1=c(0.1,0.2)), int="conf") t lwr upr 1 0.04166097 -0.11587731 0.1991993 2 0.13873100 -0.02557153 0.3030335
>
w
CQ Y
x@
w |t O}OH Q}O=kt
u= D
Q
|= @
1390 '
|vWwOv|wUwt
74
pOt "O
wtv
=
xQ W=
Q} R
w x@
OQ= t
w |t p=Ft
u= D
Q
Q}o|t Q=Qk
|= @ "O
xO
=iDU=
w
X}NWD
X}NWD QDW}@ p}rLD
OQ t '
Q O
1 2 1 4
|= @ x t
CUO@ pOt
OvDUy p=tQv =yxOv=t}k=@ =}
#
OvDUy |]N uw}UQoQ
= Q}eDt
#
| y
w
MU=B u}@ x]@=Q =}
w
Q Q}O=kt =}
#OQ=O O Hw C B
"
> >
Ovm|t pQDvm
=yxOv=t}k=@ p=tQv `} RwD
=Q
k-s
w
u tR
res { resid(m.reg) ks.test(res, "pnorm", mean=mean(res), sd=sd(res)) <
One-sample Kolmogorov-Smirnov test data: res D = 0.1553, p-value = 0.7217 alternative hypothesis: two-sided Q |t Qy=_
"OO o
> >
wtv Q=yJ 'O} Qw=}@ |r@k
Q=O
= O xr=@vO
| y ) m
QO =Q
Q} R
wDUO Qo =
C=Q
par(mfrow=c(2,2)) plot(m.reg) 0.8
Residuals vs Fitted
Normal Q−Q
9
2
Standardized residuals
−0.4
1 0
16
−0.5
0.0
16
0.5
−2
−1
0
1
Fitted values
Theoretical Quantiles
Scale−Location
Residuals vs Leverage
9
1.5
2
3
−1.0
0.5
0
1
18
−1
1.0 0.5
1
2
Standardized residuals
9
16 18
Cook’s distance16
0.0
Standardized residuals
18
−1
18
0.0
Residuals
0.4
9
−1.0
−0.5
0.0
0.5
0.00
0.05
0.10
Fitted values
=yxOv=t}k=@ x@
w Q
0.15
0.5
0.20
0.25
Leverage
=
wtv V}=tv
\ @ t | yQ=O
%34
pmW %R=
O
w
Q}o Q=Qk
=Q | vwQ O N R= w O
y=0 \
w
N p L
O}=@ pY=L pmW %xDi=}
CUDQ=@a
Q=O
wtv Q=yJ u}=
Q Q}O=kt ?UL Q@ =yxOv=t}k=@ Q}O=kt
VR= @
O O
" y v u
=Wv
w}UQoQ
75
=
u
wtv xm CU= |vat u}O@ 'OvwW s}kDUt \N l} V}=tv x@ l}ORv xOv=t}k=@
Q=O
\
Ovm|t
=kv "OyO|t u=Wv
O
\
= O =t}k=@
O =D
xW} Q
swO
=Q x W OQ= v U= | yx v
wtv u}=
Q=O
=Q
OvQ=O
=
|O } R
Q}F-=D
u
w}UQoQ \N
xm
|wQ
|]=kv
=Q
Q |krD R}v
wtv
=iDU= Q} R QwDUO
xO
plot(m.reg, which = 1) w | =iD 2 O "O W
t xO
U=
O a R=
1
w |t 'QDW}@
=
R= u= D
O
O a |
wtv |DL
Qiv=
| yQ=O
=H@ Q}N= Om
QO
qqplot
w |O=
scale-location
wtv s}UQD
plot(m.reg, which = 2) "
Q
=kv
wtv
=iDU= Q} R
xO
Q=O
wtv
w
x@ q=@
O =D
O a
Q=O
u=
=
wtv sUQ
| yQ=O
Q Ovm|t sUQ
= O
wvax@ Ov=wD|t
C B \
=Q
Q
|= @
pmW u}rw= xm
w |t =yQ=Owtv sUQ
u= D
u=v}t]= "O
OvDUy xOv=t}k=@ Q}O=kt
|= @ "
6
CiQ V}B R}v
wtv
%
CQ Y
Q=O
pYi
R= x v
%
"OO o
"O
wtv
Q=O
Cook's distance
wtv u}=
Q=O
4
O =t}k=@
|w
"
xm 'OyO|t u=Wv
qqplot
= Q
%p t v
Q}B p=tQv `} RwD
"
u} QDoQR@ 'Ovr@
=kv Qo =
O
| yp t
xrY=i
Q
|= @
2 2 1 4
w |t u=v}t]= xrY=i O=H}=
| y ) m R= u= D
Q
|= @
x { read.table("E:/R_les/data/gen_reg.txt", header=T) m.reg { lm(x$gene2~x$gene1) new { data.frame(x$gene1 { sort(x$gene1)) pred.w.clim = predict(m.reg, newdata=new, interval="condence",level=0.95) plot(x$gene2~x$gene1, pch=20) abline(m.reg, col="blue") lines(x$gene1,pred.w.clim ,2],col="red", lty=2) lines(x$gene1,pred.w.clim ,3],col="red", lty=2) pred = predict(m.reg, interval="condence") print(pred) pred1 = predict(m.reg, interval="condence") ,1,drop=F] print(pred1) legend(-1, 1.2, c("obs. data", "predict", "Lower b.", "Upper b."), pch=c(20,NA,NA,NA), lty=c(0,1,2,2), lwd=c(0,1,1,1), col=c("black","blue","red","red")) <
<
<
<
O |t CUO@ Q} R
" }
QDtm
u
Okt
Q=
xU pt=W xm
w |t xO}t=v 1
"O W
O =Wt
u x y
AIC
xm Owtv
Q CU= OwHwt
|= @ "
R
=iDU=
xO
w
O N QO
|=
x]@=
xm OwW|t
w |t xDi=}
R= u= D
=iDU=
xO
trees
O}vm =QH=
"
trees
=Q
wtv
Q=O
Q
=
w
= O
Q
j i | y ) m |= H=
O u}@ xU}=kt
VR= @ | yp t
=F
=@
Q
|= @
Q CU= QD?U=vt
|=xO=O R= p t |= @ "
Q} R QwDUO xm CU= |i=m CU= uwDU
>
=@ O}v=wD|t xm
Q |t x@U=Lt
OO o
AIC x] =
@
l} Qy
Q
w |t xDiQo Q_v
|= @ w O W
QO
trees
=
Q
"
1. Akaike's An Information Criterion
O
| yxO=O |= @ p t wO u
O}vm xU}=kt
=Q
wvm =
=yu sy
|vWwOv|wUwt
76
obs. data predict Lower b. Upper b.
0.0 −1.0
−0.5
x$gene2
0.5
1.0
1390 '
−1.0
−0.5
0.0
0.5
x$gene1
&95 u
=v}tY= xrY=i =@ uw}UQoQ
Q=O
wtv l} V}=tv
lm1 { lm(Volume ~ Height Girth, data=trees) AIC(lm1) 1] 155.4692 lm2 { lm(Volume ~ Height + Girth, data=trees) AIC(lm2) 1] 176.9100 >
<
>
>
>
<
%44
pmW
`H=Qt
77
`H=Qt
1] Crawley, Micheal J., (2007) The R Book, John Wiley & Sons Ltd, 942p. 2] Longhow Lam, (2008) An introduction to R, Business 212p.
&
Decision Amsterdam,
3] Maindonald J. H., (2008) Using R for Data Analysis and Graphics Introduction, Code and Commentary, Centre for Mathematics and Its Applications, Australian National University., 96p. 4] Paradis E., (2005) R for Beginners, Institut des Sciences de l' Evolution Universite Montpellier II France, 76p. 5] Rossiter D. G., (2007) Introduction to the R Project for Statistical Computing for use at ITC, International Institute for Geo-information Science & Earth Observation Enschede (NL), 143p. 6] Seefeld, K., Linder, E., (2007) Statistics Using R with Biological Examples, University of New Hampshire, Durham, NH Department of Mathematics & Statistics, 325p. 7] Verzani John simpleR - Using R for Introductory Statistics, 114p.