Calculating contrast values on Excel - excel

I am currently studying experimental designs in statistics and I am calculating values pertaining to 2^3 factorial designs.
The question that I have is particularly with the calculations of the "contrasts".
My goal of this question is to learn how to use the table "Coded Factors" and "Total" in order to get the values "Contrast" using the IF THEN function in Excel.
For example, Contrast A is calculated as : x - y . Where
x = sum of the values in the Total, where the Coded Factor A is + .
And y= sum of the values in the Total, where the Coded Factor A is - .
This would be rather simple, but for the interactions it is a bit more complex.
For example, contrast AC is obtained as : x - y . Where
x = sum of the values in the Total, where the product of Coded Factor A and that of C becomes + .
And y = sum of the values in the Total, where the product of Coded Factor A and that of B becomes - .
I would really appreciate your help.
Edited:
Considering the way how IF statements work, I thought that it might be a good idea to convert the + into 1 and - into -1 to make the calculation straight forward.

Convert all +/- to 1/-1. Use some cells as helper..
Put in these formulas :
J2 --> =LEFT(J1)
K2 --> =MID(J1,2,1)
L2 --> =MID(J1,3,1)
Put
J3 --> =IF(J$2="",1,INDEX($B3:$D3,MATCH(J$2,$B$2:$D$2,0)))
and drag to L10. Then
M3 --> =J3*K3*L3*G3
and drag to M10. Lastly,
M1 --> =SUM(M3:M10)
How to use : Input the Factor comb in cell J1 and the result will be in M1.
Idea : separate the factor text > load the multiplier > multiply Total values with multiplier > get sum.
Hope it helps.

Related

Distributing data with lower and upper boundaries in Excel

Here's a link to a screenshot with the formula used in Column B and some sample data
I have a spreadsheet with 48 rows of data in column A
The values range from 0 to 19
The average of these 48 rows = 8.71
the standard deviation of the population = 3.77
I've used the STANDARDIZE function in excel in column B to return the Z-score of each item in column A given that I know the mean (8.71), std dev (3.77), and x (whatever is in column A).
For example (row 2) has:
x = 2
z = -1.779
Using the z value, I want to create an lower (4) and upper (24) boundary and calculate what the value would be in this 3rd column.
Essentially, if x = 0 (min value), then z = -2.3096, and columnC = 4 (lower boundary condition)
Conversely, if x = 19 (max value), then z = 2.9947, and columnC = 19 (upper boundary condition)
and then all other values between 0 to 19 would be calculated....
Any ideas how I can accomplish this with a formula in the column C?
So if your lowest original value is 0 and your highest is 19 and you want to re-distribute them from 4 to 24 and we assume that both are linear that means:
Since both are linear we have to use these formulas:
we develope the first to c so we get
and replace the c in the second equation with that so we get
and develope this to m as follows
If we put this togeter with our third equation above we get:
So we finally have equations for m = and c = and we can use the numbers from our old and new lower and upper bound to get:
you can use these values with
where x is are your old values in column A and y is the new distributed value in column B:
Some visualization if you change the boundaries:
Idea for a non-linear solution
If you want 4 and 24 as boundaries and the mean should be 12 the solution cannot be linear of course. But you could use for example any other formula like
So you can use this formula for column D y2 with the following values a, b, c as well as calculating the mean, min and max over column D y2.
Then use the solver:
Goal is: Mean $M$15 should be 12
secondary conditions: $M$16 = 4 (lower boundary) and $M$17 = 24 (upper boundary)
variable cells are a, b and c: $M$11:$M$13
The solver will now adjust the values a, b and c so that you get very close to your goal and to get these results:
The min is 4 the max is almost 24 and the mean is almost 12 that is probably the closest you can get with a numeric method.

Find a growth rate that creates values adding to a determined total

I am trying to create a forecast tool that shows a smooth growth rate over a determined number of steps while adding up to a determined value. We have variables tied to certain sales values and want to illustrate different growth patterns. I am looking for a formula that would help us to determine the values of each individual step.
as an example: say we wanted to illustrate 100 units sold, starting with sales of 19 units, over 4 months with an even growth rate we would need to have individual month sales of 19, 23, 27 and 31. We can find these values with a lot of trial and error, but I am hoping that there is a formula that I could use to automatically calculate the values.
We will have a starting value (current or last month sales), a total amount of sales that we want to illustrate, and a period of time that we want to evaluate -- so all I am missing is a way to determine the change needed between individual values.
This basically is a problem in sequences and series. If the starting sales number is a, the difference in sales numbers between consecutive months is d, and the number of months is n, then the total sales is
S = n/2 * [2*a + (n-1) * d]
In your example, a=19, n=4, and S=100, with d unknown. That equation is easy to solve for d, and we get
d = 2 * (S - a * n) / (n * (n - 1))
There are other ways to write that, of course. If you substitute your example values into that expression, you get d=4, so the sales values increase by 4 each month.
For excel you can use this formula:
=IF(D1<>"",(D1-1)*($B$1-$B$2*$B$3)/SUMPRODUCT(ROW($A$1:INDEX(A:A,$B$3-1)))+$B$2,"")
I would recommend using Excel.
This is simply a Y=mX+b equation.
Assuming you want a steady growth rate over a time with x periods you can use this formula to determine the slope of your line (growth rate - designated as 'm'). As long as you have your two data points (starting sales value & ending sales value) you can find 'm' using
m = (y2-y1) / (x2-x1)
That will calculate the slope. Y2 represents your final sales goal. Y1 represents your current sales level. X2 is your number of periods in the period of performance (so how many months are you giving to achieve the goal). X1 = 0 since it represents today which is time period 0.
Once you solve for 'm' this will plug into the formula y=mX+b. Your 'b' in this scenario will always be equal to your current sales level (this represents the y intercept).
Then all you have to do to calculate the new 'Y' which represents the sales level at any period by plugging in any X value you choose. So if you are in the first month, then x=1. If you are in the second month X=2. The 'm' & 'b' stay the same.
See the Excel template below which serves as a rudimentary model. The yellow boxes can be filled in by the user and the white boxes should be left as formulas.

Excel - Multiply Until Total Reached

I want to multiply x*y until x>=20, then multiply z that value and have the results displayed as two values, the multiple and multiple*z
The question behind the formula is, how many boxes of x capacity do I need to have a total capacity of 20 liters and how much does that cost.
x = volume of bottle
y = number of bottles in a box
z = price per box
This could be done very easily by hand, but I've been playing (with little effect) in excel for a while and would like a solution.
I hope that makes sense
I rather think what you would like is the formula provided by #Jeeped but for:
I want to multiply x*y until x>=20, then multiply z that value and have the results displayed as two values, the multiple and multiple*z
label two arrays from 1 to 20 for columns and rows as shown, populate V1 with the price per box and in B2:
=IF(AND($A2*B$1>20,A2>=20),"",$A2*B$1)
and in X2:
=IF(B2="","",$V$1*B2)
with both formulae copied across 19 columns and those two sets of 20 formulae then copied down 19 rows. The result should be similar to:

Conditional Interpolation Excel

I have the following excel setup that is extremely massive but here is a simplified setup:
Site1 X-Given Y-Given Site2 X-New-Given Y-Interpolated
A 10 400 A 25 550
A 20 500 A 25 550
A 30 600 A 26 560
A 40 700 B 27 570
A 50 800 B 30 600
B 10 400 B 15 450
B 20 500 B 25 550
B 30 600 B 30 600
What I'm trying to accomplish is to have each Y-Interpolated only interpolate based upon its specific site and not have any cross over. So site A would only interpolate with site A, and same with site B... so on and so forth.
I'm using the interpolate excel addin which has the following syntax:
=interpolate(x_array,y_array,x_given)
Thanks for the help!
You could try this worksheet function alternative... with data in A1:E9, enter this in F2 and fill down:
=FORECAST(E2,IF(MMULT(ROW(B$2:B$9)-LOOKUP(0,(B$2:B$9>=E2)/(A$2:A$9=D2),ROW(B$2:B$9))-0.5,1)^2<1,C$2:C$9),B$2:B$9)
Update: Here's a slightly shorter alternative entered with CTRL+SHIFT+ENTER
=PERCENTILE(IF(A$2:A$9=D2,C$2:C$9),PERCENTRANK(IF(A$2:A$9=D2,B$2:B$9),E2,20))
This assumes a positive relationship between variables and returns values at both boundaries.
Background
If you're going to use worksheet functions for this, the obvious approach is to find the neighboring two points to X: (X1,Y1) and (X2,Y2). Then calculate Y using:
Y = Y1 + (X - X1) * (Y2 - Y1) / (X2 - X1)
The problem is that this leads to a lengthy formula involving six INDEX/MATCH combinations and six more conditions for restricting data to the specified site. This leads one to look for other options...
1. The first formula looks complicated but all it's doing is applying a straight line fit based on the two neighboring points for the same site. Evaluating the formula for the third row above - by highlighting each part of the formula and pressing F9 - gives:
=FORECAST(26,{FALSE;500;600;FALSE;...},{10;20;30;40;...})
FORECAST ignores non-numeric data so the result is the same as just using {500,600} and {20,30} for the 2nd and 3rd arguments. You can use F9 on other parts of the formula to break it down further - I'll leave details to you. (The MMULT(...,1) part just changes the argument to an array so you can enter the formula without array-entry.)
2. The second formula is easier to follow. First note that in Excel percentiles are calculated by linear interpolation and the IF part is just restricting the numeric data to the specified site. Assuming data is increasing it follows that we can find the k-value in the PERCENTILE formula that matches the lookup value in the x-range and return the y-range value with that k-value. For the example in question:
26 =PERCENTILE({10,20,30,40,50},0.4)
560 =PERCENTILE({400,500,600,700,800},0.4)
To calculate the value of 0.4 the PERCENTRANK can be used which is inverse to PERCENTILE:
0.4 =PERCENTRANK({10,20,30,40,50},26)
0.4 =PERCENTRANK({400,500,600,700,800},560)
The formula above follows by combining these two functions, the last argument is set to 20 for full precision (Excel stores values internally to around 15-17 digits of precision).
Because the tool that you're using is based on a .xll add in for excel, you(or we) can not modify the code or create a custom version of interpolate that allows adding conditions.
Instead, you'll have to filter your data apart and then run the custom-function on the filtered datasets.

How do I perform a monte carlo simulation in Open Office?

I am trying to generate some ranges for a problem I am working on. These rangers are going to be based on the sum of the ratio's of a bunch of numbers. So for example, the constant's are 5 6 and 7.
The ranges I get will be 5/x + 6/y + 7/z = S
I want x, y, and z to come out of a list of numbers I have - say .5, .6, .7, .8, .9, and 1
So If I run 100 iterations of this, I want the spreadsheet to randomly fill a value in X from that list of numbers, another random selection for y, and yet another for z.
And like I said, I want that sum, S, to be calculated 100 times in such a way that I will get a range of values for S.
I have been trying to figure out how to do this without the use of macros.
Here's one way to do it. Create a table of x, y, and z input values. Put a column to the left of the table with the number of each input value (1...N). Say that you have 10 potential input values for each. So your table is in A1:D10 with 1 through 10 in column A and the x values in B, y values in C, and z valued in D.
Then you can select a random value of the x values by writing =VLOOKUP(10*RAND()+1,$A$1:$D$10,2,TRUE). This randomly selects a number between 0 and 10 and looks up the x value matching the A column that matches the number, rounded down. E.g. the random number is 4.3 -- then it will select the 4th value. Replace the third parameter in the VLOOKUP column with 3 for y values and 4 for z values...
If you don't have any other data in columns A:D, you can generalize this with =VLOOKUP(count($A:$A)*RAND()+1,$A:$D,2,TRUE).

Resources