ÿþW y r ó w n a n i e o d p o r n e n a
b Bd y g r u b e . W p By w d a n y c h
n a m o d e l e p r o s t e j r e g r e s j i
W y k o n a w c a :
G r z e g o r z K r u c z e k
G r u p a w i c z e n i o w a 1
R o k a k a d e m i c k i 2 0 1 5 / 2 0 1 6
N u m e r y c z n e a l g o r y t m y i n |y n i e r s k i e
1
S p i s t r e [c i
D a n e w e j [c i o w e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
T o k p o s t p o w a n i a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2
D a n e w e j [c i o w e
x y x y
1 0 . 8 1 5 9 9 8 5 0 . 8 4 5 3 1 8 6 0 2 2 1 2 0 . 2 9 5 3 3 8 1 1 2 0 . 2 8 0 9 1 6 9 5 3
2 1 . 1 1 4 1 9 0 8 8 1 . 1 1 6 8 3 6 5 9 5 2 2 2 1 . 6 1 8 5 8 2 4 2 2 1 . 6 2 0 9 5 6 1 9 8
3 2 . 7 3 8 0 3 5 4 2 . 7 3 3 6 3 3 9 7 3 2 3 2 2 . 6 2 6 4 7 5 3 5 2 2 . 6 7 9 5 8 7 3 8 3
4 3 . 1 9 4 9 7 7 1 1 3 . 2 3 2 8 2 9 5 8 3 2 4 2 3 . 6 6 7 2 8 7 7 7 2 3 . 6 4 2 6 6 6 2 2 5
5 2 8 . 0 4 7 9 8 2 8 7 4 . 0 3 1 8 2 9 3 0 7 2 5 2 4 . 1 8 5 2 8 4 3 4 2 4 . 1 5 5 2 4 7 3 5 6
6 5 . 5 0 0 0 7 5 9 7 5 . 5 3 6 8 2 5 3 2 2 2 6 2 5 . 0 1 5 4 2 0 1 3 2 5 . 0 0 7 6 4 8 0 9 2
7 6 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7 3 6 . 6 5 9 6 7 8 3 9 3 6 . 7 2 0 2 7 8 7 9 6
1 8 1 7 . 9 7 2 8 1 4 8 2 1 7 . 9 2 9 1 5 1 5 7 7 3 8 3 7 . 3 2 7 7 2 2 0 8 3 7 . 2 8 9 4 6 6 8 6 4
1 9 1 8 . 1 6 0 0 6 0 9 1 1 8 . 1 5 7 4 7 6 2 8 7 3 9 3 0 . 7 8 8 2 8 0 8 9 3 8 . 7 8 1 1 4 9 3 7 8
2 0 0 . 2 7 8 3 4 3 3 3 1 9 . 2 7 9 0 5 5 6 9 2 4 0 3 9 . 3 6 1 2 0 6 7 3 3 9 . 4 3 4 1 0 6 0 1 6
3
T o k p o s t p o w a n i a :
1 : W y b r a n y p r o g r a m : R v 3 . 2 . 0
2 . W c z y t a n i e w s p ó Br z d n y c h x i y p u n k t ó w z o d d z i e l n y c h p l i k ó w M x n i M y n :
x = s c a n ( f i l e = " M x n . t x t " )
R e a d 4 0 i t e m s
y = s c a n ( f i l e = " M y n . t x t " )
R e a d 4 0 i t e m s
P r o g r a m p o t w i e r d z i B w c z y t a n i e z a Bo |o n e j l i c z n y e l e m e n t ó w .
3 . W y p l o t o w a n i e d a n y c h :
p l o t ( y ~ x )
4 . U t w o r z e n i e m o d e l u r e g r e s j i l i n i o w e j :
r a m k a d a n y c h : d s = d a t a . f r a m e ( x = x , y = y )
r e g r e s j a l i n i o w a : m . l m = l m ( y ~ x , d a t a = d s )
p o d s u m o w a n i e m o d e l u : s u m m a r y ( m . l m )
C a l l :
l m ( f o r m u l a = y ~ x , d a t a = d s )
4
R e s i d u a l s :
M i n 1 Q M e d i a n 3 Q M a x
- 2 2 . 7 2 2 1 - 2 . 1 3 8 7 - 0 . 0 0 1 7 1 . 8 1 5 8 2 4 . 6 5 7 6
C o e f f i c i e n t s :
E s t i m a t e S t d . E r r o r t v a l u e P r ( > | t | )
( I n t e r c e p t ) 3 . 8 0 7 2 8 2 . 2 5 0 8 9 1 . 6 9 1 0 . 0 9 8 9 .
x 0 . 8 1 8 1 2 0 . 0 9 8 1 5 8 . 3 3 5 4 . 1 6 e - 1 0 * * *
- - -
S i g n i f . c o d e s : 0 * * * 0 . 0 0 1 * * 0 . 0 1 * 0 . 0 5 . 0 . 1 1
R e s i d u a l s t a n d a r d e r r o r : 7 . 1 5 o n 3 8 d e g r e e s o f f r e e d o m
M u l t i p l e R - s q u a r e d : 0 . 6 4 6 4 , A d j u s t e d R - s q u a r e d : 0 . 6 3 7 1
F - s t a t i s t i c : 6 9 . 4 8 o n 1 a n d 3 8 D F , p - v a l u e : 4 . 1 5 8 e - 1 0
M o d e l m a d u |e o d c h y l e n i e s t a n d a r d o w e .
W y p l o t o w a n i e d a n y c h z w p a s o w a n f u n k c j s k l e j a n :
l a y o u t ( 1 )
p l o t ( x ~ y )
l i n e s ( l o w e s s ( y , x ) )
5
d e f i n i c j a w y d r u k u : o p = p a r ( m f r o w = c ( 2 , 2 ) , p t y = " s " )
w y p l o t o w a n i e w y k r e s ó w d o t y c z c y c h m o d e l u : p l o t ( m . l m )
T e o r a z p o p r z e d n i e w y k r e s y w y r a zn i e w s k a z u j p u n k t y o d s t a j c e o d m o d e l u i
z a b u r z a j c e g o .
6
w c z y t a n i e n o w e j b i b l i o t e k i : l i b r a r y ( M A S S )
o b l i c z e n i e o d l e g Bo [c i C o o k a : d l = c o o k s . d i s t a n c e ( m . l m )
o b l i c z e n i e w a r t o [c i z e s t a n d a r y z o w a n y c h r e s z t : r = s t d r e s ( m . l m )
w y t y p o w a n i e p u n k t ó w o d l e g By c h o w i c e j n i | j e d n j e d n o s t k o d l e g Bo [c i o d
w y k r e s u f u n k c j i o b r a z u j c e g o m o d e l :
a = c b i n d ( d s , d l , r )
a [ d l > 1 / 4 0 , ]
x y d l r
5 2 8 , 0 4 7 9 8 4 , 0 3 1 8 2 9 0 , 2 0 5 7 3 2 - 3 , 2 3 9 7 1
1 4 1 3 , 2 5 7 5 5 3 9 , 3 1 1 1 4 0 , 2 1 0 8 3 8 3 , 5 0 7 3 2 1
2 0 0 , 2 7 8 3 4 3 1 9 , 2 7 9 0 6 0 , 2 7 0 5 3 8 2 , 2 4 3 7 4 8
3 5 3 4 , 8 5 4 7 1 1 3 , 8 9 8 8 3 0 , 2 5 7 8 7 9 - 2 , 6 6 8 5 3
3 9 3 0 , 7 8 8 2 8 3 8 , 7 8 1 1 5 0 , 0 4 9 1 7 7 1 , 4 0 2 4 1 3
Z n a l e z i e n i e w z b i o r z e 1 0 p u n k t ó w o n a j w i k s z y c h o d l e g Bo [c i a c h C o o k a
w k o l e j n o [c i o d n a j w i k s z e j d o n a j m n i e j s z e j :
r a b s = a b s ( r )
a = c b i n d ( d s , d l , r , r a b s )
a s o r t e d = a [ o r d e r ( - r a b s ) , ]
a s o r t e d [ 1 : 1 0 , ]
x y d l r r a b s
1 4 1 3 , 2 5 7 5 5 3 9 , 3 1 1 1 4 0 , 2 1 0 8 3 8 3 , 5 0 7 3 2 1 3 , 5 0 7 3 2 1
5 2 8 , 0 4 7 9 8 4 , 0 3 1 8 2 9 0 , 2 0 5 7 3 2 - 3 , 2 3 9 7 1 3 , 2 3 9 7 1
3 5 3 4 , 8 5 4 7 1 1 3 , 8 9 8 8 3 0 , 2 5 7 8 7 9 - 2 , 6 6 8 5 3 2 , 6 6 8 5 2 7
2 0 0 , 2 7 8 3 4 3 1 9 , 2 7 9 0 6 0 , 2 7 0 5 3 8 2 , 2 4 3 7 4 8 2 , 2 4 3 7 4 8
3 9 3 0 , 7 8 8 2 8 3 8 , 7 8 1 1 5 0 , 0 4 9 1 7 7 1 , 4 0 2 4 1 3 1 , 4 0 2 4 1 3
1 0 , 8 1 5 9 9 9 0 , 8 4 5 3 1 9 0 , 0 1 4 5 9 3 - 0 , 5 3 3 0 8 0 , 5 3 3 0 7 6
2 1 , 1 1 4 1 9 1 1 , 1 1 6 8 3 7 0 , 0 1 3 9 7 9 - 0 , 5 2 8 4 1 0 , 5 2 8 4 1 1
4 0 3 9 , 3 6 1 2 1 3 9 , 4 3 4 1 1 0 , 0 1 3 6 2 5 0 , 5 0 4 0 0 5 0 , 5 0 4 0 0 5
3 2 , 7 3 8 0 3 5 2 , 7 3 3 6 3 4 0 , 0 1 0 1 6 - 0 , 4 8 3 2 1 0 , 4 8 3 2 1 4
4 3 , 1 9 4 9 7 7 3 , 2 3 2 8 3 0 , 0 0 9 0 0 8 - 0 , 4 6 4 2 0 , 4 6 4 2 0 2
w c z y t a n i e n o w e j b i b l i o t e k i : l i b r a r y ( c a r )
w y p l o t o w a n i e w y k r e s u p r z e d s t a w i a j c e g o o d l e g Bo [c i C o o k a d l a k a |d e g o
p u n k t u : i n f l u e n c e P l o t ( l m ( y ~ x ) , m a i n = " i n f l u e n c e P l o t " , s u b = " P r o m i e D K ó Bk a j e s t
p r o p o r c j o n a l n y d o o d l e g Bo [c i C o o k a " )
S t u d R e s H a t C o o k D
1 4 4 . 2 0 8 4 3 7 0 . 0 3 3 1 4 2 8 6 0 . 4 5 9 1 7 1 0
2 0 2 . 3 7 7 0 8 4 0 . 0 9 7 0 4 5 5 1 0 . 5 2 0 1 3 2 4
7
A u t o m a t y c z n e w y s z u k a n i e p u n k t ó w z a b u r z a j c y c h m o d e l :
i n f l u e n c e . m e a s u r e s ( l m ( y ~ x ) )
I n f l u e n c e m e a s u r e s o f
l m ( f o r m u l a = y ~ x ) :
d f b , 1 _ d f b , x d f f i t c o v , r c o o k , d h a t i n f
1 - 0 , 1 6 9 1 7 9 0 , 1 4 4 7 2 8 - 0 , 1 6 9 2 1 1 , 1 4 6 1 , 4 6 E - 0 2 0 , 0 9 3 1
2 - 0 , 1 6 5 5 4 9 0 , 1 4 1 0 3 7 - 0 , 1 6 5 6 1 , 1 4 3 1 , 4 0 E - 0 2 0 , 0 9 1
3 - 0 , 1 4 0 7 8 1 0 , 1 1 7 0 1 - 0 , 1 4 1 1 1 , 1 3 3 1 , 0 2 E - 0 2 0 , 0 8 0 1
4 - 0 , 1 3 2 4 0 3 0 , 1 0 9 2 0 3 - 0 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 , 0 7 3 7 7 4 0 , 2 1 9 0 4 1 0 , 3 1 7 7 9 0 , 9 9 6 4 , 9 2 E - 0 2 0 , 0 4 7 6
4 0 - 0 , 0 8 0 0 3 8 0 , 1 4 0 7 7 8 0 , 1 6 3 4 4 1 , 1 5 2 1 , 3 6 E - 0 2 0 , 0 9 6 9
P u n k t y z a b u r z a j c e m o d e l z o s t a By o z n a c z o n e s y m b o l e m *
5 . R e g r e s j a l i n i o w a z " r c z n y m " u s u n i c i e m d a n y c h :
U s u n i c i e p u n k t ó w o n a j w i k s z y c h o d l e g Bo [c i a c h C o o k a :
m . l m 2 = l m ( y ~ x , s u b s e t = - c ( 5 , 1 4 , 2 0 , 3 5 , 3 9 ) )
P o d s u m o w a n i e m o d e l u : s u m m a r y ( m . l m 2 )
C a l l :
l m ( f o r m u l a = y ~ x , s u b s e t = - c ( 5 , 1 4 , 2 0 , 3 5 , 3 9 ) )
R e s i d u a l s :
M i n 1 Q M e d i a n 3 Q M a x
- 0 . 1 1 1 7 2 8 - 0 . 0 2 4 6 0 8 0 . 0 0 5 6 4 8 0 . 0 2 5 2 0 6 0 . 0 6 4 5 8 5
C o e f f i c i e n t s :
9
E s t i m a t e S t d . E r r o r t v a l u e P r ( > | t | )
( I n t e r c e p t ) - 0 . 0 1 1 4 2 2 8 0 . 0 1 3 7 3 7 4 - 0 . 8 3 2 0 . 4 1 2
x 1 . 0 0 0 5 0 1 4 0 . 0 0 0 6 0 7 3 1 6 4 7 . 5 8 8 <