# #   zn00000V0^000B 0h00^X 0RH00) 
 
 l i b r a r y ( r s t u d i o a p i )     # # P a c k a g e s   k0&
 
 
 
 d   < -   r e a d . c s v ( ' T a b l e 3 _ 1 . c s v ' ) 
 
 n   < -   n r o w ( d ) 
 
 Y   < -   d $ Y 
 
 X   < -   d $ X               # # R
 
 d a t a   < -   l i s t ( n = n ,   Y = Y   , X = X )     # # R
 
 
 
 # #   s t a n n0000000
 
 P o i s s o n R e g B   < - ' 
 
 d a t a   { 
 
     i n t < l o w e r = 0 >   n ;               / /   n u m b e r   o f   c u s t o m e r 
 
     i n t < l o w e r = 0 >   Y [ n ] ;         / /   n u m b e r   o f   r y o k o u 
 
     r e a l < l o w e r = 0 >   X [ n ] ;         / / y u t o r i 
 
 } 
 
 
 
 p a r a m e t e r s   { 
 
     r e a l   b e t a 0 ; 
 
     r e a l   b e t a 1 ; 
 
     r e a l   r [ n ] ; 
 
     r e a l < l o w e r = 0 >   s ; 
 
 } 
 
 
 
 t r a n s f o r m e d   p a r a m e t e r s   { 
 
     r e a l < l o w e r = 0 >   t h e t a [ n ] ; 
 
     f o r   ( i   i n   1 : n )   { 
 
         t h e t a [ i ]   =   e x p ( b e t a 0   +   b e t a 1   *   X [ i ]   +   r [ i ] ) ; 
 
     } 
 
 } 
 
 
 
 m o d e l   { 
 
     f o r   ( i   i n   1 : n )   { 
 
         Y [ i ]   ~   p o i s s o n ( t h e t a [ i ] ) ; 
 
     } 
 
     b e t a 0   ~   n o r m a l ( 0 ,   1 0 0 ) ; 
 
     b e t a 1   ~   n o r m a l ( 0 ,   1 0 0 ) ; 
 
     r   ~   n o r m a l ( 0 ,   s ) ; 
 
 } 
 
 ' 
 
 #   S t a n n0[L
 
 l i b r a r y ( r s t a n ) 
 
 f i t b   < -   s t a n ( m o d e l _ c o d e = P o i s s o n R e g B , d a t a = d a t a , i t e r = 2 0 0 0 , c h a i n s = 4 , 
 
                         p a r s = c ( ' b e t a 0 ' , ' b e t a 1 ' ,   ' r ' ,   ' s ' ) ,   s e e d = 2 3 4 5 6 , c o n t r o l = l i s t ( a d a p t _ d e l t a = 0 . 9 ) ) 
 
 f i t b 
 
 t r a c e p l o t ( f i t b ,   p a r s = c ( ' b e t a 0 ' , ' b e t a 1 ' ) ) 