
R Under development (unstable) (2013-09-05 r63851) -- "Unsuffered Consequences"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ic.infer)
> 
> mat <- as.matrix(swiss)
> colnames(mat) <- NULL
> covmat <- cov(swiss)
> linmod <- lm(swiss)
> linmodwt <- lm(swiss,weights=abs(-23:23))
> linmodfac <- lm(1/time~poison+treat+poison:treat,boot::poisons)
> 
> ## check normal functionality for covariance matrix
> all.R2(covmat,ui=diag(1,5))
 [1] 0.0000000 0.1246649 0.0000000 0.0000000 0.2150035 0.1735189 0.1246649
 [8] 0.1246649 0.2482782 0.3172607 0.0000000 0.2150035 0.1735189 0.2150035
[15] 0.1735189 0.3309201 0.1246649 0.2482782 0.3172607 0.2482782 0.3172607
[22] 0.3858919 0.2150035 0.1735189 0.3309201 0.3309201 0.2482782 0.3172607
[29] 0.3858919 0.3858919 0.3309201 0.3858919
> orlm1 <- orlm(covmat,ui=diag(c(-1,1,-1,1,1)),df.error=41)
> summary(orlm1, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
Agriculture Examination Education Catholic Infant.Mortality 


 Inequality restrictions:
     Agriculture Examination Education Catholic Infant.Mortality            
1:   -1          0           0         0        0                %*%colnames
2: A 0           1           0         0        0                %*%colnames
3:   0           0           -1        0        0                %*%colnames
4:   0           0           0         1        0                %*%colnames
5:   0           0           0         0        1                %*%colnames
         
1:  >=  0
2:  >=  0
3:  >=  0
4:  >=  0
5:  >=  0

 Note: Restrictions marked with A are active. 


Restricted model: R2 reduced from 0.706735 to 0.6993476 


Coefficients from order-restricted model: 
     R Agriculture      R Examination        R Education         R Catholic 
        -0.1546175          0.0000000         -0.9802638          0.1246664 
R Infant.Mortality 
         1.0784422 

 Note: Coefficients marked with R are involved in restrictions. 
> ice <- ic.est(coef(linmod),Sigma=vcov(linmod),ui=(diag(c(-1,1,-1,1,1))),index=2:6)
> summary(ice)
Order-restricted estimated mean with restrictions of coefficients of 
Agriculture Examination Education Catholic Infant.Mortality 


 Inequality restrictions:
     Agriculture Examination Education Catholic Infant.Mortality            
1:   -1          0           0         0        0                %*%colnames
2: A 0           1           0         0        0                %*%colnames
3:   0           0           -1        0        0                %*%colnames
4:   0           0           0         1        0                %*%colnames
5:   0           0           0         0        1                %*%colnames
         
1:  >=  0
2:  >=  0
3:  >=  0
4:  >=  0
5:  >=  0

 Note: Restrictions marked with A are active. 

Restricted estimate: 
       (Intercept)      R Agriculture      R Examination        R Education 
        62.1013116         -0.1546175          0.0000000         -0.9802638 
        R Catholic R Infant.Mortality 
         0.1246664          1.0784422 

 Note: Estimates marked with R are involved in restrictions. 
> summary(ice,brief=TRUE)
Order-restricted estimated mean with restrictions of coefficients of 
Agriculture Examination Education Catholic Infant.Mortality 


Restricted estimate: 
       (Intercept)      R Agriculture      R Examination        R Education 
        62.1013116         -0.1546175          0.0000000         -0.9802638 
        R Catholic R Infant.Mortality 
         0.1246664          1.0784422 

 Note: Estimates marked with R are involved in restrictions. 
> orr1<-or.relimp(covmat,df.error=41,ui=diag(c(-1,1,-1,1,1)))
> 
> ## check normal functionality for unnamed covariance matrix
> covmat2 <- cov(mat)
> all.R2(covmat2,ui=diag(1,5))
 [1] 0.0000000 0.1246649 0.0000000 0.0000000 0.2150035 0.1735189 0.1246649
 [8] 0.1246649 0.2482782 0.3172607 0.0000000 0.2150035 0.1735189 0.2150035
[15] 0.1735189 0.3309201 0.1246649 0.2482782 0.3172607 0.2482782 0.3172607
[22] 0.3858919 0.2150035 0.1735189 0.3309201 0.3309201 0.2482782 0.3172607
[29] 0.3858919 0.3858919 0.3309201 0.3858919
> orlm1 <- orlm(covmat2,ui=diag(c(-1,1,-1,1,1)),df.error=41)
> summary(orlm1, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
X1 X2 X3 X4 X5 


 Inequality restrictions:
     X1 X2 X3 X4 X5                   
1:   -1 0  0  0  0  %*%colnames  >=  0
2: A 0  1  0  0  0  %*%colnames  >=  0
3:   0  0  -1 0  0  %*%colnames  >=  0
4:   0  0  0  1  0  %*%colnames  >=  0
5:   0  0  0  0  1  %*%colnames  >=  0

 Note: Restrictions marked with A are active. 


Restricted model: R2 reduced from 0.706735 to 0.6993476 


Coefficients from order-restricted model: 
      R X1       R X2       R X3       R X4       R X5 
-0.1546175  0.0000000 -0.9802638  0.1246664  1.0784422 

 Note: Coefficients marked with R are involved in restrictions. 
> orr1<-or.relimp(covmat2,df.error=41,ui=diag(c(-1,1,-1,1,1)))
> 
> ## check normal functionality for linear model
> orlm1 <- orlm(linmod,ui=diag(c(-1,1,-1,1,1)))
> summary(orlm1, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
Agriculture Examination Education Catholic Infant.Mortality 


 Inequality restrictions:
     Agriculture Examination Education Catholic Infant.Mortality            
1:   -1          0           0         0        0                %*%colnames
2: A 0           1           0         0        0                %*%colnames
3:   0           0           -1        0        0                %*%colnames
4:   0           0           0         1        0                %*%colnames
5:   0           0           0         0        1                %*%colnames
         
1:  >=  0
2:  >=  0
3:  >=  0
4:  >=  0
5:  >=  0

 Note: Restrictions marked with A are active. 


Restricted model: R2 reduced from 0.706735 to 0.6993476 


Coefficients from order-restricted model: 
       (Intercept)      R Agriculture      R Examination        R Education 
        62.1013116         -0.1546175          0.0000000         -0.9802638 
        R Catholic R Infant.Mortality 
         0.1246664          1.0784422 

 Note: Coefficients marked with R are involved in restrictions. 
> orr1<-or.relimp(linmod,ui=diag(c(-1,1,-1,1,1)))
> sum(orr1)
[1] 0.6993476
> orlm1$R2
[1] 0.6993476
> 
> ## check normal functionality for linear model of unnamed data
> linmod2 <- lm(as.data.frame(mat))
> orlm1 <- orlm(linmod2,ui=diag(c(-1,1,-1,1,1)))
> summary(orlm1, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
V2 V3 V4 V5 V6 


 Inequality restrictions:
     V2 V3 V4 V5 V6                   
1:   -1 0  0  0  0  %*%colnames  >=  0
2: A 0  1  0  0  0  %*%colnames  >=  0
3:   0  0  -1 0  0  %*%colnames  >=  0
4:   0  0  0  1  0  %*%colnames  >=  0
5:   0  0  0  0  1  %*%colnames  >=  0

 Note: Restrictions marked with A are active. 


Restricted model: R2 reduced from 0.706735 to 0.6993476 


Coefficients from order-restricted model: 
  (Intercept)          R V2          R V3          R V4          R V5 
   62.1013116    -0.1546175     0.0000000    -0.9802638     0.1246664 
         R V6 
    1.0784422 

 Note: Coefficients marked with R are involved in restrictions. 
> orr1<-or.relimp(linmod2,df.error=41,ui=diag(c(-1,1,-1,1,1)))
> sum(orr1)
[1] 0.6993476
> orlm1$R2
[1] 0.6993476
> 
> ## check normal functionality for weighted linear model
> orlm1 <- orlm(linmodwt,ui=diag(c(-1,1,-1,1,1)))
> summary(orlm1, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
Agriculture Examination Education Catholic Infant.Mortality 


 Inequality restrictions:
     Agriculture Examination Education Catholic Infant.Mortality            
1:   -1          0           0         0        0                %*%colnames
2: A 0           1           0         0        0                %*%colnames
3:   0           0           -1        0        0                %*%colnames
4:   0           0           0         1        0                %*%colnames
5:   0           0           0         0        1                %*%colnames
         
1:  >=  0
2:  >=  0
3:  >=  0
4:  >=  0
5:  >=  0

 Note: Restrictions marked with A are active. 


Restricted model: R2 reduced from 0.7400627 to 0.7340304 


Coefficients from order-restricted model: 
       (Intercept)      R Agriculture      R Examination        R Education 
       63.04003588        -0.12758055         0.00000000        -1.04869971 
        R Catholic R Infant.Mortality 
        0.09597652         1.12865481 

 Note: Coefficients marked with R are involved in restrictions. 
> orr1<-or.relimp(linmodwt,df.error=41,ui=diag(c(-1,1,-1,1,1)))
> sum(orr1)
[1] 0.7340304
> orlm1$R2
[1] 0.7340304
> 
> ## check normal functionality for linear model with factors 
> ## and interactions
> orlm1 <- orlm(linmodfac,ui=diag(c(1,1,1,-1,-1)),index=2:6)
> orlm1

Constrained linear model:


Restricted model: R2 reduced from 0.8680551 to 0.8145232 

Coefficients:
   (Intercept)         poison2         poison3          treatB          treatC  
        1.8377          1.4308          2.9650          0.0000          0.0000  
        treatD  poison2:treatB  poison3:treatB  poison2:treatC  poison3:treatC  
       -0.1480         -1.8751         -1.7737         -0.5546         -0.5377  
poison2:treatD  poison3:treatD  
       -1.4189         -1.5629  

> summary(orlm1, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
poison2 poison3 treatB treatC treatD 


 Inequality restrictions:
     poison2 poison3 treatB treatC treatD                   
1:   1       0       0      0      0      %*%colnames  >=  0
2:   0       1       0      0      0      %*%colnames  >=  0
3: A 0       0       1      0      0      %*%colnames  >=  0
4: A 0       0       0      -1     0      %*%colnames  >=  0
5:   0       0       0      0      -1     %*%colnames  >=  0

 Note: Restrictions marked with A are active. 


Restricted model: R2 reduced from 0.8680551 to 0.8145232 


Coefficients from order-restricted model: 
     (Intercept)        R poison2        R poison3         R treatB 
       1.8376895        1.4307805        2.9649958        0.0000000 
        R treatC         R treatD   poison2:treatB   poison3:treatB 
       0.0000000       -0.1480075       -1.8750778       -1.7737125 
  poison2:treatC   poison3:treatC   poison2:treatD   poison3:treatD 
      -0.5545508       -0.5376984       -1.4189284       -1.5628726 

 Note: Coefficients marked with R are involved in restrictions. 
> summary(orlm1,brief=TRUE, overall.tests=FALSE)
Order-restricted linear model with restrictions of coefficients of 
poison2 poison3 treatB treatC treatD 


Coefficients from order-restricted model: 
     (Intercept)        R poison2        R poison3         R treatB 
       1.8376895        1.4307805        2.9649958        0.0000000 
        R treatC         R treatD   poison2:treatB   poison3:treatB 
       0.0000000       -0.1480075       -1.8750778       -1.7737125 
  poison2:treatC   poison3:treatC   poison2:treatD   poison3:treatD 
      -0.5545508       -0.5376984       -1.4189284       -1.5628726 

 Note: Coefficients marked with R are involved in restrictions. 
> 
> proc.time()
   user  system elapsed 
   0.85    0.06    0.92 
