par(mfrow=c(1,2)) # figure Dist. of Height for Female Participants Dist. of Height for Male Participants Density 0.00 0.02 0.04 0.06 0.08 Density 0.00 0.02 0.04 0.06 0.08 140 150 160 170 180 190 Height 140 150 160 170 180 190 Height
HISTOGRAM hist(dat[dat$gender=='f',]$h, main="dist. of Height for Female Participants", xlab="height", xlim=c(140,190), probability=t) # dat[dat$gender=='f',]$h # dat gender F dens.f = density(dat[dat$gender=='f',]$h) lines(dens.f, col='blue',lwd=2) hist(dat[dat$gender== M,]$h, main= Dist. of Height for Male Participants, xlab= Height, xlim=c(140,190), probability=t,ylim=c(0,0.08)) dens.m = density(dat[dat$gender=='m',]$h) lines(dens.m, col='green', lwd=2)
HISTOGRAM Dist. of Height for Female Participants Dist. of Height for Male Participants Density 0.00 0.02 0.04 0.06 0.08 Density 0.00 0.02 0.04 0.06 0.08 140 150 160 170 180 190 Height 140 150 160 170 180 190 Height
par(mfrow=c(1,1)) plot(dens.f,col='blue',lwd=2, ylab='density', xlim=c(140,190), main="dist. of Height by gender",xlab='height') lines(dens.m,col='green',lwd=2) legend("topleft", c('female','male'), col=c('blue','green'), cex=1.5,lwd=2)
# text(x, y, TEXT ) text(x = 157.5, y = 0.04, 'Female', col='blue', cex=2) text(x = 170, y = 0.04,'Male', col='green', cex=2) Dist. of Height by gender density 0.00 0.02 0.04 0.06 Female Male 140 150 160 170 180 190 Height
21 22 23 24 25 1 2 3 4 5 16 17 18 19 20 11 12 13 14 15 6 7 8 9 10 1 2 3 4 5 1 2 3 4 5
# plot(x,y, ) plot(dat$shoesize, dat$h, main="relationship b/w shoesize and height, xlab = 'shoesize, ylab='height, pch=19, col='red ) Relationship b/w shoesize and height height 150 160 170 180 21 22 23 24 25 26 27 28 shoesize
txt = paste("r =",round(cor(dat$shoesize,dat$h), 4)) > txt[1] "r = 0.875" # paste a=1:3 paste("s",a) => [1] "s 1" "s 2" "s 3" paste( s, a, sep= ) => [1] "s1" "s2" "s3 # round > cor(dat$shoesize,dat$h) [1] 0.8749517 > round(cor(dat$shoesize,dat$h),4) [1] 0.875
txt = paste("r =", round(cor(dat$shoesize,dat$h), 4)) text(22, 175, txt, cex = 1.5) Relationship b/w shoesize and height height 150 160 170 180 r = 0.874 21 22 23 24 25 26 27 28 shoesize
abline: abline(h = mean(dat$h), col='blue'); abline(v = mean(dat$shoesize), col='green'); H V height 150 160 170 180 r = 0.874 mean height Relationship b/w shoesize and height mean shoesize 21 22 23 24 25 26 27 28 shoesize
abline(lm(dat$h~dat$shoesize), lty=2, lwd=2) Relationship b/w shoesize and height height 150 160 170 180 r = 0.874 21 22 23 24 25 26 27 28 shoesize
plot(dat[dat$gender=='f',]$shoesize, dat[dat$gender=='f',]$h, main="relationship b/w shoesize and height", xlab='shoesize', ylab='height', cex.lab=1.5, pch=19, col='blue', xlim=c(20,29), ylim=c(140,190)) Relationship b/w shoesize and height height 140 150 160 170 180 190 Female Male 20 22 24 26 28 shoesize
plot(dat[dat$gender=='m',]$shoesize, dat[dat$gender=='m',]$h, main="relationship b/w shoesize and height", xlab='shoesize', ylab='height', cex.lab=1.5, pch=15, col='green', xlim=c(20,29), ylim=c(140,190)) Relationship b/w shoesize and height height 140 150 160 170 180 190 Female Male 20 22 24 26 28 shoesize
Relationship b/w shoesize and height height 140 150 160 170 180 190 Female Male 20 22 24 26 28 shoesize
plot(dat[dat$gender=='f',]$shoesize, dat[dat$gender=='f',]$h, main="relationship b/w shoesize and height", xlab='shoesize', ylab='height', cex.lab=1.5, pch=19, col='blue', xlim=c(20,29), ylim=c(140,190)) points(dat[dat$gender=='m',]$shoesize,dat[dat$gender=='m',]$h, pch = 15, col = 'green') legend("topleft", c('female','male'), pch =c(19,15), col = c('blue','green'), cex = 1.5) points: lines height 140 150 160 170 180 190 Female Male Relationship b/w shoesize and height 20 22 24 26 28 shoesize
dat<-read.csv("http://www.matsuka.info/data_folder/tdkreg01.csv") plot(dat, pch=20, col='blue') 100 140 180 50 100 150 200 material 2 4 6 8 10 100 140 180 price design 10 30 50 70 50 100 150 200 sales 2 4 6 8 10 10 20 30 40 50 60 70
plot(dat.pca, pch = rownames(dat.pca), cex = 1.7, col = 'blue ) 40 50 60 70 80 90 > dat.pca writing thesis interview a 88 70 65 b 52 78 88 c 77 87 89 d 35 40 43 e 60 43 40 f 97 95 91 g 48 62 83 h 66 66 65 i 78 50 48 40 50 60 70 80 90 d d writing c b g h i e b c g h i e a a f f e d d e i i a h g b thesis b g ha c c f f e d e d i i a h a h interview c g b g b f f c 40 50 60 70 80 90 40 50 60 70 80 90 40 50 60 70 80 90 40 50 60 70 80 90
( "% " = $ %&' )
! = # $ = $ % & % + $ ( & ( + + $ * & * = + $, &, *,-%! = # $ = $ % & % + $ ( & ( + + $ * & * =. 0 /0 $1 $ 2$
! " # = %&' ( = ) ( + # = ) ( ) ( # %&' ( = (, + # -, + ( # + # - # + + ( 0 + # - 0 = 1 = 1 2 = 1 2 ( 2 # 2( 2 + + + # - 2 = 1 2 ( 2 # - 2 2+ 1 = ) ( # 2+ 5 + + + # 5 1 = ) ( # ) ( # 2 ( 2-2 + 1 2 + # - 2 0 23, ( 2 # - 2 2( 2 +- 2 + + # - 2 ( 2 + # - 2
! " = $%&&'( = ()*
! $ "# = &'( ), + =, ), ), +, + =, )+, ) +, + ) +, ), + =, )+, ), +, ), + +, ), + =, )+, ), +! $ "" = &'( ), ) =, )), ), ) =, ) $, ) $ =! $ " = (/0 )
: cov(x,y) = cov(y,x) cov(x,x) = var(x) cov(ax, by) = ab*cov(x,y) cov(a+x, b+y) = cov(x,y) cov(x, Y+Z) = cov(x,y)+cov(x,z) cov(σx, ΣY)=ΣΣcov(X,Y)
" #$ = &'(( ), + = &',(), +),/( ),/((+)
( "% " = $ %&' ( * +, = $ %&' ) ( /01 = $ %&' " % ", ) 1 /01(", 2) 4 = * + * 8 " % " 2 % 32 ) 1 9 = : " ; +, = : " 9, = : " : ", ; +8 = : " : " : 2 : 2 /01(", 2) < = 1=4 " 1=4(2)
! " # = % ) *&,- # &'(. 1 ). 1! " # = % &'( ) = % &'( ) = % &'( ) = % &'( ) * &,- # = % &'( ) * & 1 # + % &'( ) * & + 1 1,- # = % &'( ),- 1 # 2,- 1 % &'( * & 1 # +.,- 1 # 2,- 1.,- 1 * & 1 #.,- 1 #. 1 3! # " = % 3 * & 1 #.3,- 1 # 3! " # = 4 " # ) &'( =.4 " #.4, 5 # =.4 # ". 4 " #. =. 1 4 # " * & + 1,- 1 # * & 1
( ) = E ( X 1 ) + E ( X 2 ) +!+ E ( X n ) = µ + µ +!+ µ = nµ ( ) = var( X 1 ) + var( X 2 ) +!+ var( X n ) = σ 2 +σ 2 +!+σ 2 = nσ 2 E X 1 + X 2 +!+ X n var X 1 + X 2 +!+ X n ( ) = E X 1 + X 2 +!+ X # n E X var X! " ( ) = var! # " n X 1 + X 2 +!+ X n n $! & = E X $! 1 # &+!+ E X $ n # & = nµ % " n % " n % n = µ $ & = 1 % n var X 2 1 ( ) +!+ 1 n var ( X 2 n) = nσ 2 = σ 2 n 2 n
dat<-read.table("http://www.matsuka.info/data_folder/aov01.txt",header=t) > head(dat) shoesize h gender affil club 1 27.0 181.4 M psy tetsudo 2 26.5 170.8 M cs tennis 3 27.5 182.3 M psy karate 4 26.5 166.8 M psy tennis 5 23.5 153.2 F cs tetsudo 6 23.0 151.6 F psy tennis > summary(dat) shoesize h gender affil club Min. :21.00 Min. :145.0 F:36 cs :35 karate :24 1st Qu.:23.50 1st Qu.:157.2 M:34 psy:35 tennis :23 Median :24.50 Median :164.0 tetsudo:23 Mean :24.82 Mean :164.1 3rd Qu.:26.38 3rd Qu.:170.9 Max. :28.00 Max. :182.3
> mean(dat$shoesize) [1] 24.82143 > mean(dat$h) [1] 164.1443 > var(dat$shoesize) [1] 2.652433 > var(dat$h) [1] 83.97352 > cov(dat[,1:2]) shoesize h shoesize 2.652433 13.05802 h 13.058023 83.97352 > cor(dat[,1:2]) shoesize h shoesize 1.0000000 0.8749517 h 0.8749517 1.0000000
)! "# = % &'( ) "* & + & = "* ( + ( + "* - + - + + "* ) + ) = " % * & + & = "! "# &'( > dat.meter = dat[,1:2]*0.01 > mean(dat.meter$h) [1] 1.641443 > mean(dat$h)*0.01 [1] 1.641443 > mean(dat$h) [1] 164.1443
*! " + $ = & '() * + ', ' + $ &, ' = & + ', ' + $ - 1 =! " + $ '() * '() > dat.h.ext5 = dat$h+5 [1] 160 153 155 181 170 167 153 163 157 169 > mean(dat.h.ext5) [1] 169.1443 > mean(dat$h) [1] 164.1443 > mean(dat$h)+5 [1] 169.1443
*! " + $ = & + ', " = + ' + & - ', $ = - ' =! " +! $ '() * '() > handshoe = dat$h+dat$shoesize > mean(handshoe) [1] 188.9657 > mean(dat$h)+mean(dat$shoesize) [1] 188.9657
! "# + % =! "# +! % = "! # + % > dat.h.meter.ext5 = dat$h*0.01+0.05 > mean(dat.h.meter.ext5) [1] 1.691443 > 0.01*mean(dat$h)+0.05 [1] 1.691443
!"# $% = ' $% ' $% ) > var(dat.meter$h) [1] 0.008397352 = ' $% $* ) = ' $ ) % * ) = $ ) ' % * ) = $ )!"# % > var(dat$h)*(0.01^2) [1] 0.008397352
!"# $ + & = ( $ + & ( $ + & = ( $ + & + + & * = ( $ + * =!"# $ * > var(dat.h.ext5) [1] 83.97352 > var(dat$h) [1] 83.97352
!"# $% + ' = ) $% + ' ) $% + ' + > var(dat.h.meter.ext5) [1] 0.008397352 > var(dat$h)*(0.01^2) [1] 0.008397352 = ) $% + ' $, + ' + = ) $ % +, + = $ + ) %, + = $ +!"# %
!"# $ + & = ( $ + & * + + *, - > var(handshoe) [1] 112.742 = ( $ + & - 2 $ + & * + + *, + * + + *, - = ( $ - + 2$& + & - + 2$* + 2$*, 2&* + 2&*, + * + - + 2* + *, + *, - = ( $ - 2$* + + * + - + & - 2&*, + *, - + 2$& 2$*, 2&* + + 2* + *, = ( $ * + - + ( & *, - + 2/01 $, & > var(dat$h)+var(dat$shoesize)+2*cov(dat$h,dat$shoesize) [1] 112.742
!"# $, $ = ' $$ ' $ ' $ = ' $ ) ' $ ) = *+, $ > cov(dat$h,dat$h) [1] 83.97352 > var(dat$h) [1] 83.97352
!"# $%, '( = * $% * $% '( * '( = * $'%( * $% '( * '( $% + * $% * '( = $'* %( $'* % * ( $'* % * ( + $'* % * ( = $' * %( * % * ( = $' -!"# %, ( > cov(dat.meter$h,dat.meter$shoesize) [1] 0.001305802 > (0.01*0.01)*cov(dat$h,dat$shoesize) [1] 0.001305802
!"# $ + &, ( + ) = + $ + & + $ + & ( + ) + ( + ) = + $ + & ( + ) + $ + & ( + ) + ( + ) $ + & + + $ + & + ( + ). = + $ + & ( + ) + $ + & + ( + ) + $ + & + ( + ) + + $ + & + ( + ) = + $( + (& + $) + &) $ + + & ( + + ) = $( + (+ & + $+ ) + + &) $( (+ & $+ ) + & + ) = + &) + & + ) =!"# &, ) > cov(dat.h.ext5,dat.ss.ext1) [1] 13.05802 > cov(dat$h,dat$shoesize) [1] 13.05802
!"# $, & + ( = * $ * $ & + ( * & + ( = * $ & + ( * $ & + ( * & + ( $ + * $ * & + (. = * $ & + ( * $ * & + ( * $ * & + ( + * $ * & + ( = * $ & + ( * $ * & + ( = * $& + $( * $ * & + * $ * ( = * $& * $ * & + * $( * $ * ( =!"# $, & +!"# $, ( > cov(dat$h,handshoe) [1] 97.03154 > cov(dat$h,dat$shoesize)+cov(dat$h,dat$h) [1] 97.03154
!"# $1 + $2, )1 + )2 = + $1 + $2 + $1 + $2 )1 + )2 + )1 + )2 = + $1 + $2 )1 + )2 + $1 + $2 + )1 + )2 = + $1)2 + $1)2 + $2)1 + $2)2 + $1 + )1 + + $1 + )2 + + $2 + -1 + + $2 + )2 = + $1)1 + $1 + )1 + + $1)2 + $1 + )2 + + $2)1 + $2 + )1 + + $2)2 + $2 + )2 =!"# $1, )1 +!"# $1, )2 +!"# $2, )1 +!"# $2, )2 =..!"# $ / + ) 0 / 0 123. $ / =..!"# $ / + ) 0 =. 123 $ / +..!"# $ / + $ 0 / / 0 / / 04/ =. 123 $ / +..!"# $ / + $ 0 / / 05/