Sta$s$cs ¡& ¡Experimental ¡Design ¡ with ¡R ¡
Barbara ¡Kitchenham ¡ Keele ¡University ¡
1 ¡
Sta$s$cs & Experimental Design with R Barbara - - PowerPoint PPT Presentation
Sta$s$cs & Experimental Design with R Barbara Kitchenham Keele University 1 Correla$on and Regression 2 Correla$on The associa$on between two
1 ¡
2 ¡
– If ¡both ¡variables ¡are ¡standardized ¡then ¡ploQed ¡ – Elipse ¡shape ¡indicates ¡an ¡associa$on ¡ » Narrower ¡the ¡elipse ¡the ¡closer ¡ρ~1(+ve) ¡or ¡-‑1 ¡(-‑ve) ¡ – Circular ¡shape ¡indicates ¡no ¡associate ¡with ¡ρ~0 ¡
3 ¡
4 ¡
5 ¡
6 ¡
5000 15000 25000 35000 10 20 30 40 50 60 70
Data from ICL
Effort LoC
A B ¡
7 ¡
8 ¡
9 ¡
10000 20000 30000 40000
20 40 60 80 x y
10 ¡
11 ¡
5000 15000 25000 35000 10 20 30 40 50 60 70 X Y * * * * * * * * *
– Replace ¡X ¡and ¡y ¡values ¡at ¡extremes ¡with ¡25 ¡(low) ¡75 ¡(high) ¡ percen$le ¡values ¡ – 0.407 ¡sig.level=.276 ¡
– Not ¡es$mate ¡of ¡Pearson’s ¡r ¡ – New ¡correla$on ¡robust ¡to ¡changes ¡in ¡distribu$on ¡ – Based ¡on ¡trimming ¡univariate ¡outliers ¡ – corb(x,y,corfun=pbcor,nboot=599) ¡ – rpb=.441 ¡Boostrap ¡CI=(-‑0.44, ¡0.97) ¡
– Removed ¡based ¡on ¡MGV ¡ ¡then ¡use ¡Pearson ¡(r=0.91) ¡ – Need ¡to ¡adjust ¡Test ¡value ¡& ¡cri$cal ¡value ¡ ¡
12 ¡
13 ¡
10000 20000 30000 40000 50 100 150 200 250 300 x y
relplot
10000 20000 30000 40000 50 100 150 200 250 300 X Y * * * * * * ** * * * * * * * * * * * * * * * * * * *
14 ¡
15 ¡
16 ¡
17 ¡
b1=0.9018 ¡ b0=-‑0.0097 ¡ b1=0.57441 ¡ b0 ¡=-‑0.07613 ¡
1 2 3
1 2 rho=0.5 x y
1 2 3
1 2 3 rho=0.9 x y
18 ¡
19 ¡
20 ¡
21 ¡
22 ¡
23 ¡
10000 20000 30000 40000 50 100 150 200 250 300 loc effort
24 ¡ 10000 20000 30000 40000 50 100 150 200 250 300 Loc Effort
25 ¡
7.5 8.0 8.5 9.0 9.5 10.0 10.5 1 2 3 4 5 Log(Loc) Log(Effort)
26 ¡
27 ¡
28 ¡
1 2
1 2 t Quantiles Studentized Residuals(fit)
29 ¡
Distribution of Errors
Residuals Density
1 2 0.0 0.1 0.2 0.3 0.4 0.5 0.6
Normal Curve KernelDensity Curve
30 ¡
31 ¡
7.5 8.5 9.5 10.5
0.5 1.5 log(loc) Component+Residual(log(effort)) 1.5 2.0 2.5 3.0
1 2 log(dur) Component+Residual(log(effort)) 1 2 3
0.0 1.0 co Component+Residual(log(effort))
Component + Residual Plots
– ncvTest() ¡func$on ¡
best ¡fitng ¡line ¡(Spread-‑Level ¡Plot) ¡
– Can ¡indicate ¡possible ¡non-‑linearity ¡in ¡Y ¡variable ¡
– Only ¡when ¡mul$ple ¡X ¡variables ¡ – Measure ¡extent ¡to ¡which ¡parameter ¡standard ¡devia$on ¡for ¡a ¡ parameter ¡is ¡expanded ¡ ¡
– If ¡square ¡root ¡of ¡vif ¡>2 ¡there ¡may ¡be ¡a ¡problem ¡
32 ¡
33 ¡ 5 10 20 50 100 0.02 0.05 0.20 0.50 2.00 5.00
Spread-Level Plot for fit
Fitted Values Absolute Studentized Residuals
34 ¡
35 ¡
regressed ¡on ¡other ¡variables ¡
36 ¡
0.10 0.15 0.20 0.25
1 2 Circle size proportional to Cook's distance Hat-Values Studentized Residuals 7 16 23
results ¡Slide ¡(12) ¡
– update(fit,subset=-‑c(7,16)) ¡
37 ¡
38 ¡
39 ¡
0.10 0.15 0.20 0.25 0.30
1 2 Hat-Values Studentized Residuals 4 23
– E.g. ¡Co ¡(which ¡stands ¡for ¡company) ¡in ¡the ¡ICLBT ¡database ¡
– The ¡effect ¡of ¡the ¡“missing” ¡dummy ¡variable ¡is ¡included ¡in ¡the ¡ intercept ¡ – If ¡only ¡one ¡dummy ¡variable ¡
– Effect ¡of ¡missing ¡dummy ¡variable ¡– ¡Effect ¡of ¡dummy ¡variable ¡
40 ¡
41 ¡
42 ¡
– Forwards ¡stepwise ¡starts ¡with ¡no ¡variables ¡and ¡adds ¡one ¡at ¡a ¡ $me ¡ – Backwards ¡starts ¡with ¡all ¡variables ¡and ¡removes ¡them ¡one ¡at ¡a ¡ $me ¡ – Stepwise ¡goes ¡forward ¡but ¡re-‑assesses ¡all ¡variables ¡as ¡each ¡new ¡
– Based ¡on ¡Akaike ¡Informa$on ¡Criteria ¡(AIC) ¡
– With ¡limited ¡number ¡of ¡variables ¡
43 ¡
44 ¡
– I.e. ¡creates ¡k ¡different ¡training ¡& ¡valida$on ¡sets ¡at ¡random ¡ – Based ¡on ¡changes ¡to ¡the ¡R-‑square ¡sta$s$c ¡
45 ¡
46 ¡
47 ¡
10000 20000 30000 40000 50 100 150 200 250 300 loc effort
48 ¡
5 10 15 20 25 50 100 150 200 250 300 dur effort
49 ¡
50 100 150 200 250 300 50 100 150 200
Multiple regression using Lowess
effort Fitted values 1 2 3 4 5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
Values on log scale
log(effort) Log Fitted Values
50 ¡
51 ¡
52 ¡ 10000 20000 30000 40000 50 100 150 200 250 300 loc effort
53 ¡
50 100 150 200 250 300 100 200 300 400 500 effort tsfitted
54 ¡