How to run ATPVBAEN.Xlam for t-test equal variance assuming? - data-analysis

I found a code for t-test for comparing 2 variances as below:
Application.Run "ATPVBAEN.XLAM!Pttestv", Range("B50:B289"), Range("C50:C228"), Range("O3"), False, 0.05
But it uses for un-equal variance, how about equal variance?

Related

glmer - odds ratios & interpreting a binary outcome

Dear Members of the community,
It is my understanding that the summary() of a lmer model outputs values that are in line with the unit of measure specified by the nature of the outcome (e.g. reaction time in milliseconds for a given trial);
But what of glmer models where the outcome is strictly binary ? (e.g. 0/1 score for a given trial) ?
I read that in such a case the concept of odd-ratios allows to quantify results on a logit scale but am unsure how to implement this for the current example :
> summary(recsem.full)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [
glmerMod]
Family: binomial ( logit )
Formula: score ~ 1 + modality + session + (1 + modality | PID) + (1 +
modality | stim)
Data: recsem
Control: glmerControl(optimizer = "nmkbw")
AIC BIC logLik deviance df.resid
1634.7 1685.5 -808.4 1616.7 2063
Scaled residuals:
Min 1Q Median 3Q Max
-7.3513 0.1192 0.2441 0.4284 2.1665
Random effects:
Groups Name Variance Std.Dev. Corr
PID (Intercept) 1.8173 1.3481
modality 1.1752 1.0841 -0.44
stim (Intercept) 0.5507 0.7421
modality 0.2508 0.5008 0.66
Number of obs: 2072, groups: PID, 37; stim, 28
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.1191 0.2972 7.129 1.01e-12 ***
modality 0.6690 0.2815 2.376 0.01749 *
session -0.4239 0.1302 -3.255 0.00113 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) modlty
modality -0.269
session -0.251 -0.008
Looking at the fixed effects my interpretation is that both predictors are significant but how do I interpret / transform the estimates into something more tangible ?
Thank you very much in advance for any insights you might be able to share;
Have a nice day !

What is the most efficient way to pass some constant arguments to a function in Julia?

Suppose I have the following function
function foo(x::Float64, a::Float64)
if do_some_intense_stuff(a)
return bar(x)
else
return baz(x)
end
end
Let's assume that at runtime a will be a constant. But x will not. I have to run foo() many times, so I would like it to run as fast as possible, which means running do_some_intense_stuff as rarely as possible. Because a is a constant, at runtime we know which branch the if statement should take.
So ideally, I'd do the following:
foowrapper(x) = foo(x,a)
Y = [foowrapper(x) for x in lots_of_x]
and it would be a lot faster than
Y = [foo(x,a) for x in lots_of_x]
But that's not what happens. I don't blame the compiler for not optimizing my code since I didn't explicitly tell it that foo() will only ever be called with the constant value of a. But is there a good way for me to do that?
Of course, I can always get rid of foo and just write that if statement in the global scope, but that seems inelegant because the rest of the program does not care about the output of do_some_intense_stuff()
Update:
To benchmark the solution suggested below, I implemented the functions as follows. I also modified the declaration of foo() to make a an integer, for obvious reasons:
function bar(x::Float64)
return 2 * x
#println("Ran bar for value ",x)
end
function baz(x::Float64)
return -2 * x
#println("Ran baz for value ",x)
end
#memoize function do_some_intense_stuff(a::Int64)
return isprime(a + 32614262352646106013967035018546810367130464316134634614)
end
And defined lots_of_x = 1.0:1.0:1000.0.
Here is the output of #benchmark Y = [foo(x,a) for x in lots_of_x ] with and without memoize:
Without:
BenchmarkTools.Trial:
memory estimate: 109.50 KiB
allocs estimate: 5001
--------------
minimum time: 6.858 ms (0.00% GC)
median time: 6.924 ms (0.00% GC)
mean time: 7.067 ms (0.77% GC)
maximum time: 78.747 ms (49.00% GC)
--------------
samples: 707
evals/sample: 1
With:
BenchmarkTools.Trial:
memory estimate: 39.19 KiB
allocs estimate: 2001
--------------
minimum time: 97.500 μs (0.00% GC)
median time: 98.801 μs (0.00% GC)
mean time: 108.897 μs (1.37% GC)
maximum time: 2.099 ms (93.76% GC)
--------------
samples: 10000
Perhaps caching the result of your call to do_some_intense_stuff(a) will help, e.g. using Memoize.jl.

Comparision between vectors fails

I am implementing the simplex algorithm for an university course.
The code works well, but when I'm testing with the provided test problem I do not get the right result.
One line in the code compares two vectors pMinC and zeros(n,1) where n is the dimension of pMinC to decide whether the result is optimal.
In the second iteration I get the vector pMinC = [ 0.00000 4.00000 3.50000 -33.00000 -3.00000 0.00000 0.00000] which is obviously bigger than zero, but the algorithm terminates.
The code looks like this:
while(done == false)
% compute pMinC
if (sum(pMinC > zeros(n,1)))
% do stuff
else
done = true;
endif
endwhile
Why does the comparison work first and then fails the second time?
The problem is you are comparing a n*1 vector with a 1*n vector. In this case octave broadcasts the variable (similar to matlabs bsxfun) resulting in a matrix. The sum of a matrix is a vector.
Use if any(pMinC>0) to fix the problem.
The comparison is summing up the results of the logical tests, not the sum of the positive deviations. Is that what you want?
>> sum(pMinC > zeros(1,7))
ans =
2
>> pMinC > zeros(1,7)
ans =
0 1 1 0 0 0 0
>>

Plotting a 3D function with Octave

I am having a problem graphing a 3d function - when I enter data, I get a linear graph and the values don't add up if I perform the calculations by hand. I believe the problem is related to using matrices.
INITIAL_VALUE=999999;
INTEREST_RATE=0.1;
MONTHLY_INTEREST_RATE=INTEREST_RATE/12;
# ranges
down_payment=0.2*INITIAL_VALUE:0.1*INITIAL_VALUE:INITIAL_VALUE;
term=180:22.5:360;
[down_paymentn, termn] = meshgrid(down_payment, term);
# functions
principal=INITIAL_VALUE - down_payment;
figure(1);
plot(principal);
grid;
title("Principal (down payment)");
xlabel("down payment $");
ylabel("principal $ (amount borrowed)");
monthly_payment = (MONTHLY_INTEREST_RATE*(INITIAL_VALUE - down_paymentn))/(1 - (1 + MONTHLY_INTEREST_RATE)^-termn);
figure(2);
mesh(down_paymentn, termn, monthly_payment);
title("monthly payment (principal(down payment)) / term months");
xlabel("principal");
ylabel("term (months)");
zlabel("monthly payment");
The 2nd figure like I said doesn't plot like I expect. How can I change my formula for it to render properly?
I tried your script, and got the following error:
error: octave_base_value::array_value(): wrong type argument `complex matrix'
...
Your monthly_payment is a complex matrix (and it shouldn't be).
I guess the problem is the power operator ^. You should be using .^ for element-by-element operations.
From the documentation:
x ^ y
x ** y
Power operator. If x and y are both scalars, this operator returns x raised to the power y. If x is a scalar and y is a square matrix, the result is computed using an eigenvalue expansion. If x is a square matrix. the result is computed by repeated multiplication if y is an integer, and by an eigenvalue expansion if y is not an integer. An error results if both x and y are matrices.
The implementation of this operator needs to be improved.
x .^ y
x .** y
Element by element power operator. If both operands are matrices, the number of rows and columns must both agree.

Find a pattern of binary numbers using shift-right and bitwise-AND?

I'm attempting to write a function in assembly that will detect if a longer binary number contains a smaller binary pattern.
Example:
Does 100111 contain 1001?
When I read this problem I figured that I would do a bitwise-AND with the large number and its smaller pattern while shifting right (logical) each time in a loop.
So, in my head I thought it would do:
100111 AND 1001 = 0
Shift-right 1
010011 AND 1001 = 0
Shift-right 1
001001 AND 1001 = 1 // Pattern FOUND!
and repeat this until either the number was shifted until it was zero or the AND returned 1.
However, I think I must have something confused because this is returning 1 for most things I put in, on the first run of the loop. Am I confused on my usage of AND?
The problem is that "partial matches" also return a non-zero value for your AND check:
100111 AND 001001 = 000001
So this tests if any of the bits match, but you want to make sure all bits are the same. The result of the AND needs to be equal to the pattern you are searching:
x = 100111
if (x AND 1001 == 1001)
print "found"
Bitwise AND does not work the way you expect (judging from the samples and ignoring the notation which seems to suggest you are using bitwise AND as the logical AND of bits). AND only takes the bits that are set to 1 "into account". E.g 1111 AND 1001 == 1001.
You need to use XOR and compare against 0 for match (remember the mask the bits you are not comparing from the result). In your example a match is found when (N ^ 1001) & 1111 == 0000
In order to make sure that both the 0 and 1 bits match your search pattern, you need to do something like this:
if ((InputPattern AND SearchMask) == SearchPattern)
{
// then match
}
The SearchMask should be all 1 bits, of a length equal to your SearchPattern. For example, you could have SearchMask == 1111, SearchPattern == 1001.
You should AND and then test against the search pattern:
if ((TestPattern & SearchPattern) == SearchPattern)
{
// then match
}
(where & represents bitwise AND)