1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
R version 3.2.4 (2016-03-10) -- "Very Secure Dishes"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-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.
> ### test the extended interpreter for the left hand side of linear hypotheses
> ### Features:
> ### - fully recursive expression parser built upon a small code fragment copied over from base::codetools
> ### - the parser stops if any of the following conditions is not met:
> ### - any variable must be addressed only once
> ### - all operators and functions must finally evaluate to a a real valued literal
> ### - function parameters must not denote an effect name
> ### - effects can not be multiplied or divided by another effect
> ### - additive or subtractive terms involving an effect and a numeric
> ### constants must not be specified
> ### - coefficients associated with named effects must not evaluate to zero
> ###
> ### Examples:
> ### x1 + x1 == 0 -> not accepted
> ### x1 + x2 -1 == 0 -> not accepted
> ### x1 * x2 == 0 -> not accepted
> ### x1 / x2 == 0 -> not accepted
> ### f(x1) == 0 -> not accepted if x1 denotes an effect
> ### 2*3 == 6 -> not accepted because no effect was named
> ### x1 + x2*0 == 0 -> not accepted because this is likely an oversight
> ### x1 + 3*(4-5+1)*x2 == 0 -> not accepted because this is likely an oversight
> ### x1*3/0 == 0 -> not accepted because coefficient would become infinite
> ### log(-1)*x1 == 0 -> not accepted, because the result is not finite
> ### x1 + x2 +0 == 0 -> accepted because adding zero does not make a difference
> ### sin(pi/2) * x1 == 0 -> accepted if 'pi' is not an effect
> ### sin(Pi/2) * x1 == 0 -> accepted if 'Pi' is not an effect. However, if the environment does not define Pi the evaluation may still fail.
>
>
> tmp <- multcomp:::chrlinfct2matrix( c( l01 = " x1 - x2 = 2"
+ , l02 = " x2 + 3 * x3 = 1"
+ , l03 = " (x1 - x2) - (x3 - x4) = 0"
+ , l04 = "+(x1 - x2)*-2 - (1/3+2)*( +x3 - 2*x4 ) = -1"
+ , l05 = "-(x1 - x2)*-2 - (1/3+2)*( -x3 - 2*x4 ) = -2"
+ , l06 = "-(x1 - x2)*-2 - (1/3+2)*( -x3 - 2*x4 )*7/-10 = -3"
+ , l07 = "-1*(x1:x2 - x1:x2:x3) - x3 = -4"
+ , l08 = "-(x1:x2 - x1:x2:x3) - x3 = -4"
+ , l09 = "-(x1:x2 - 3*x1:x2:x3)*-2 - x3 -5/3*-x4= -5"
+ , l10 = "--cos(pi/2)*x1 - 10*(log(10^-3)+1)*-x2 -10^-3*x3 + -exp(-2)*x4= -6"
+ , l11 = " x1 + x2 + 0 = -7"
+ ), c('x1','x2','x3','x4','x1:x2','x1:x2:x3') )
>
> stopifnot(max(abs( dK <- tmp$K -
+ rbind( c( 1, -1, 0, 0, 0, 0 )
+ , c( 0, 1, 3, 0, 0, 0 )
+ , c( 1, -1, -1, 1, 0, 0 )
+ , c( -2, 2, -(1/3+2), 2*(1/3+2), 0, 0 )
+ , c( 2, -2, (1/3+2), 2*(1/3+2), 0, 0 )
+ , c( 2, -2, (1/3+2)*-7/10, 2*(1/3+2)*-7/10, 0, 0 )
+ , c( 0, 0, -1, 0, -1, 1 )
+ , c( 0, 0, -1, 0, -1, 1 )
+ , c( 0, 0, -1, -5/3*-1, 2, -6 )
+ , c( --cos(pi/2), 10*(log(10^-3)+1), -10^-3, -exp(-2), 0, 0 )
+ , c( 1, 1, 0, 0, 0, 0 )
+ ))) < sqrt(.Machine$double.eps))
>
> stopifnot(max(abs( tmp$m -
+ c( 2
+ , 1
+ , 0
+ , -1
+ , -2
+ , -3
+ , -4
+ , -4
+ , -5
+ , -6
+ , -7
+ ))) < sqrt(.Machine$double.eps))
>
> expectFail <- function(testname, x) {
+ if ( class(x) != 'try-error' ) {
+ stop(testname, ' unexpectedly succeeded. Result is: ', paste(x, collapse = ', '),'\n')
+ }
+ message(testname, ' expectedly failed. Message is: ', attr(x,'condition')$message, '\n')
+ }
>
> expectSucc <- function(testname, x,expected) {
+ if ( class(x) == 'try-error' ) {
+ stop(testname, ' unexpectedly failed. Message is: ', attr(x,'condition')$message, '\n')
+ }
+ message(testname, ' expectedly succeeded.',
+ ' Expected result is: ', paste(x, collapse = ', '), ', ',
+ ' actual result is: ', paste(x, collapse = ', '), '\n')
+
+ stopifnot(all.equal(as.vector(x$K),expected$K))
+ stopifnot(all.equal(as.vector(x$m),expected$m))
+ stopifnot(all(as.vector(x$alternative) %in% expected$alternative))
+ }
>
> expectFail('test 01', try( multcomp:::chrlinfct2matrix( c('x1 - x1 = 0'), c('x1','x2')), silent = T))
test 01 expectedly failed. Message is: multcomp:::expression2coef::walkCode::sub: multiple occurence of 'x1' found within expression 'x1 - x1'
>
> expectFail('test 02', try( multcomp:::chrlinfct2matrix( c('x1 - X2 = 0'), c('x1','x2')), silent = T))
test 02 expectedly failed. Message is: multcomp:::chrlinfct2matrix: variable(s) 'X2' not found
>
> expectFail('test 03', try( multcomp:::chrlinfct2matrix( c('x1 - x2 -1 = 0'), c('x1','x2')), silent = T))
test 03 expectedly failed. Message is: multcomp:::expression2coef::walkCode::sub: forming a difference between a constant and an effect as in 'x1 - x2 - 1' is not supported
>
> expectFail('test 04', try( multcomp:::chrlinfct2matrix( c('x1 * x2 = 0'), c('x1','x2')), silent = T))
test 04 expectedly failed. Message is: multcomp:::expression2coef::walkCode::mul: the multiplication of effects 'x1', 'x2' as in 'x1 * x2' is not supported
>
> expectFail('test 05', try( multcomp:::chrlinfct2matrix( c('x1 / x2 = 0'), c('x1','x2')), silent = T))
test 05 expectedly failed. Message is: multcomp:::expression2coef::walkCode::div: cant't divide by effect 'x2' in 'x1/x2'
>
> expectFail('test 06', try( multcomp:::chrlinfct2matrix( c('x1 - exp(x2) = 0'), c('x1','x2')), silent = T))
test 06 expectedly failed. Message is: multcomp:::expression2coef::walkCode::eval: within 'exp(x2)', the term 'x2' must not denote an effect. Apart from that, the term must evaluate to a real valued constant
>
> expectFail('test 07', try( multcomp:::chrlinfct2matrix( c('sin(Pi)*x1 = 0'), c('x1','x2')), silent = T))
test 07 expectedly failed. Message is: multcomp:::expression2coef::walkCode::eval: the evaluation of the expression 'sin(Pi)' failed with "object 'Pi' not found"
>
> expectFail('test 08', try( multcomp:::chrlinfct2matrix( c('3*4 = 0'), c('x1','x2')), silent = T))
test 08 expectedly failed. Message is: multcomp:::expression2coef: The lhs expression '3 * 4' contains a numeric offset term evaluating to 12. This is either an internal error or a misspecification from your part. If so, please pull these offsets to the right-hand side of the equation
>
> expectFail('test 09', try( multcomp:::chrlinfct2matrix( c('x1 + 3*(4-5+1)*x2 = 0'), c('x1','x2')), silent = T))
test 09 expectedly failed. Message is: multcomp:::expression2coef::walkCode::mul: The constant part of the expression '3 * (4 - 5 + 1) * x2' evaluates to zero. This would zero out the effect(s) 'x2'
>
> expectFail('test 10', try( multcomp:::chrlinfct2matrix( c('x1*3/0 = 0'), c('x1','x2')), silent = T))
test 10 expectedly failed. Message is: multcomp:::expression2coef::walkCode::div: can't divide by '0' in 'x1 * 3/0'
>
> expectFail('test 11', try( multcomp:::chrlinfct2matrix( c('log(-1)*x1 = 0'), c('x1','x2')), silent = T))
test 11 expectedly failed. Message is: multcomp:::expression2coef::walkCode::eval: the expression 'log(-1)' did not evaluate to a real valued constant. Result is 'NaN'
Warning message:
In log(-1 * 1) : NaNs produced
>
> expectSucc('test 12', try( multcomp:::chrlinfct2matrix( c('x1 -x2 -1/2*(-x2:x3 + x4:x5) = 0'),
+ c( 'x1', 'x2', 'x3', 'x4', 'x5', 'x2:x3','x4:x5')), silent = T),
+ expected = list( K = c( 1, -1, 0, 0, 0, 1/2, -1/2),
+ m = 0, alternative = 'two.sided'))
test 12 expectedly succeeded. Expected result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided, actual result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided
>
> expectSucc('test 13', try( multcomp:::chrlinfct2matrix( c( 'x1 -x2 -1/2*(--x2:x3 + x4:x5) = 0'),
+ c( 'x1', 'x2', 'x3', 'x4', 'x5', 'x2:x3','x4:x5')), silent = T),
+ expected = list( K = c( 1, -1, 0, 0, 0, -1/2, -1/2),
+ m = 0, alternative = 'two.sided'))
test 13 expectedly succeeded. Expected result is: c(1, -1, 0, 0, 0, -0.5, -0.5), 0, two.sided, actual result is: c(1, -1, 0, 0, 0, -0.5, -0.5), 0, two.sided
>
> expectSucc('test 14', try( multcomp:::chrlinfct2matrix( c( 'x1 -x2 -1/2*(`-x2:x3` + x4:x5) = 0'),
+ c( 'x1', 'x2', 'x3', 'x4', 'x5', '-x2:x3','x4:x5')), silent = T),
+ expected = list( K = c( 1, -1, 0, 0, 0, -1/2, -1/2),
+ m = 0, alternative = 'two.sided'))
test 14 expectedly succeeded. Expected result is: c(1, -1, 0, 0, 0, -0.5, -0.5), 0, two.sided, actual result is: c(1, -1, 0, 0, 0, -0.5, -0.5), 0, two.sided
>
> expectSucc('test 15', try( multcomp:::chrlinfct2matrix( c( 'x1 -x2 -1/2*(-(x2:x3) + x4:x5) = 0'),
+ c( 'x1', 'x2', 'x3', 'x4', 'x5', 'x2:x3','x4:x5')), silent = T),
+ expected = list( K = c( 1, -1, 0, 0, 0, 1/2, -1/2),
+ m = 0, alternative = 'two.sided'))
test 15 expectedly succeeded. Expected result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided, actual result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided
>
> expectSucc('test 16', try( multcomp:::chrlinfct2matrix( c( 'x1 -x2 -1/2*(-1*x2:x3 + x4:x5) = 0'),
+ c( 'x1', 'x2', 'x3', 'x4', 'x5', 'x2:x3','x4:x5')), silent = T),
+ expected = list( K = c( 1, -1, 0, 0, 0, 1/2, -1/2),
+ m = 0, alternative = 'two.sided'))
test 16 expectedly succeeded. Expected result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided, actual result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided
>
>
>
> expectSucc('test 17', try( multcomp:::chrlinfct2matrix( c( 'x1 -x2 -1/2*(+-+--x2:x3:x4 + x4:x5) = 0'),
+ c( 'x1', 'x2', 'x3', 'x4', 'x5', 'x2:x3:x4','x4:x5')), silent = T),
+ expected = list( K = c( 1, -1, 0, 0, 0, 1/2, -1/2),
+ m = 0, alternative = 'two.sided'))
test 17 expectedly succeeded. Expected result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided, actual result is: c(1, -1, 0, 0, 0, 0.5, -0.5), 0, two.sided
>
> expectFail('test 18', try( multcomp:::chrlinfct2matrix( c( 'x1 - x2 - 1/2 * ( x2:-x3 + x4:x5 ) = 0'),
+ c( 'x1','x2','x2:x3','x4:x5')), silent = T))
test 18 expectedly failed. Message is: multcomp:::chrlinfct2matrix: variable(s) 'x2:-x3' not found
>
>
>
> proc.time()
user system elapsed
0.916 0.016 0.930
|