Gamma_inv returns error if random number is over 0.96 - excel

Gamma_inv returns an error if the random number passed to it is higher than roughly 0.96. This happens in both Excel and with VBA. I am running a Monte Carlo, and this only happens 10 or so times in over 40,000 runs. Here is how I am using it. alpha and beta are always >0. If "gammatrunc"= 1, I get the errors. If I set it to 0.95, I get no errors:
alpha = B * B * bsy2 ^ -2
beta = bsy2 * bsy2 / B
rand = Rnd * gammatrunc
B = WorksheetFunction.GAMMA_Inv(rand, alpha, beta)
The errors look like this:
Output with error messages
I'd appreciate any thoughts on why this is happening.
Thanks

You can use this function to study a variable whose distribution may be skewed.
If any argument is text, Gamma_Inv returns the #VALUE! error value.
If probability < 0 or probability > 1, Gamma_Inv returns the #NUM! error value.
If alpha ≤ 0 or if beta ≤ 0, Gamma_Inv returns the #NUM! error value.
Given a value for probability, Gamma_Inv seeks that value x such that GAMMA_DIST(x, alpha, beta, TRUE) = probability. Thus, precision of Gamma_Inv depends on precision of Gamma_Dist. Gamma_Inv uses an iterative search technique. If the search has not converged after 100 iterations, the function returns the #N/A error value.
https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.gamma_inv
You can add some controls in your code, like MIN and MAX, using VBA.

Related

What's the difference between these two methods for calculating a weighted median?

I'm trying to calculate a weighted median, but don't understand the difference between the following two methods. The answer I get from weighted.median() is different from (df, median(rep(value, count))), but I don't understand why. Are there many ways to get a weighted median? Is one more preferable over the other?
df = read.table(text="row count value
1 1. 25.
2 2. 26.
3 3. 30.
4 2. 32.
5 1. 39.", header=TRUE)
# weighted median
with(df, median(rep(value, count)))
# [1] 30
library(spatstat)
weighted.median(df$value, df$count)
# [1] 28
Note that with(df, median(rep(value, count))) only makes sense for weights which are positive integers (rep will accept float values for count but will coerce them to integers). This approach is thus not a full general approach to computing weighted medians. ?weighted.median shows that what the function tries to do is to compute a value m such that the total weight of the data below m is 50% of the total weight. In the case of your sample, there is no such m that works exactly. 28.5% of the total weight of the data is <= 26 and 61.9% is <= 30. In a case like this, by default ("type 2") it averages these 2 values to get the 28 that is returned. There are two other types. weighted.median(df$value,df$count,type = 1) returns 30. I am not completely sure if this type will always agree with your other approach.

Why percentage calculation in excel gives me incorrect numbers

I have the below numbers
Potiential Customers = 2791 and enrolled customers are 45
In excel I calculated the percentage as 45/2791 gives me 16.12 but in calculator it gives me 0.0161,..
I dont understand what. I also checked the "set Percision as displayed", still gives me the incorrect percentages. Any idea why?
When I calculated as 45/2791 multiplied by 100 it doesn't give the correct results and when I did 45/2791 multiplied by 0.10 it gives me the correct numbers same as calculator.
Any settings I have to change? Please let me know.
when multiplied by 0.10
When multiplies by 100
Please be clear about your question. Do you want to calculate Percentage or simple division?. Percentage is always calculated/total * 100.
You are getting 0.0161.. because you have not multiplied by 100.
After multiplying by 100, Percentage = ( 45/2791 ) * 100 = 1.61% i.e Correct
Why result = 16.12.. because ( 45/2791 ) * 1000 = 16.12% i.e Wrong
Hope it has cleared your doubts.

For what sample mean would the p-value be equal to 0.05

It's a homework question. I am not looking for exact answer but need a direction. I have following question
H0: µ = 30
HA: µ != 30
We know that the sample standard deviation is 10 and the sample size is 70. For what sample mean would the p-value be equal to 0.05? Assume that all conditions necessary for inference are satisfied.
I am solving it as following
As our H0 is based on equal sign, so our test is two sided, we need to check both for small and larger values.
The P value of 0.05 in the probability table is equal to a z score of 1.65.
We need to calculate S.E and then find mean using Z formula
S.D = 10
n = 70
se <- S.D/sqrt(n)
# Z= (xbar- µ)/ S.E => xbar = Z * S.E + µ
xbar = (1.65*se)+30
So, in this way i get one mean value. but our test is two sided. so i need another mean value. I am not getting how can I solve it. Any suggestion or idea will be appreciable.
Thanks

Excel Floor function

I am confused regarding excel floor function. Mathematically, floor (x) is the largest integer not greater than x. Following this definition, I expected,
Floor( -3,-2) to display -4 , but it displays -2.
Can somebody explain why?
This might help:
FLOOR function - Rounds a number down, toward zero
FLOOR.PRECISE function - Rounds a number down to the nearest integer or to the nearest multiple of significance. Regardless of the sign of the number, the number is rounded down.
=FLOOR(-3,-2) is -2
=FLOOR.PRECISE(-3,2) is -4
Using negative significance revert behavior.
From documentation:
If number is positive and significance is negative, FLOOR returns the #NUM! error value.
If the sign of number is positive, a value is rounded down and adjusted toward zero.
If the sign of number is negative, a value is rounded down and adjusted away from zero. If
number is an exact multiple of significance, no rounding occurs.
However, testing positive and negative number and significance I get following result:
Significance > 0:
Any number: Round down (toward negative infinity)
Significance < 0:
Number < 0: Round up (toward positive infinity)
Number >= 0: #NUM!
Significance = 0:
Number = 0: 0
Number <> 0: #DIV!
Number - the value to be rounded.
Significance - the function rounds the Number specified above down to the nearest multiple of this value.
Floor(-3,-2)
As here -3 is the number and -2 is the significance So if we see multiple of -2 than 0(-2*1),-2(-2*1),-4(-2*2),-6(-2*3) but here NUMBER -3 is round down to the nearest multiple of -2 is itself -2(Answer).
Try this Floor(-3,-4) gives 0.

Probability of Failure in Excel

Suppose I have probability of failure p = 0.2. Failure is defined as 0 and success is 1. How can I simulate this on an Excel cell (such that I can drag it down)? That is, a formula that yields 0 with a probability of 20% and 1 with 80%.
Thanks!
The rand function returns a decimal between 0 and 1. If it's less than .2, you can consider it a failure.
=IF(RAND()<0.2,0,1)
RAND() will give a random number between 0 and 1, so you can then use it directly in an IF:
=IF(RAND()<0.2,0,1)

Resources