Reverse percentage calculation - math

I have below 5 items with percentage
P1 = 10%
P2 = 30%
P3 = 50%
P4 = 60%
P5 = 10%
Total = 160%
Actual Percentage = 1.6 (160/100)
Now suppose i want to decrease percentage lets say by 0.6, so actual percentage value will be 1.
But How much i should decrease the percentage from all products? so that my Final Total will be 100%.
Is there any reverse percentage calculation generic formula?
Thanks

you don't call that as 160% but instead, 1.6 portion counts for 100%.
updated percentages:
P1 = (10/160) * 100 = 6.25%
P2 = 18.75%
P3 = 31.25%
P4 = 37.5%
P5 = 6.25%
Now no matter how much value you decrease from total, if you decrease it proportionally from every item, the perscentages should remain the same.
Percentage actually denotes portion of total.

Related

how do I find the mean value of one variable for every 5th percentile of another variable

I want to find the mean of one numeric variable for each percentile of another numeric variable. To essentially replicate this graph (Marian et al(2012) but for my own data:
Figure 6. Average orthographic neighborhood size as a function of word frequency.
Frequency bins are evenly spaced divisions of words in 5% increments. Bin one represents the average orthographic neighborhood size of the top 5% most frequent words in the language, bin twenty represents the average orthographic neighborhood size of the 5% least frequent words.
I have tried the following:
tapply(quantile(CLEARPOND$word_frequency, probs = c(.05, .10, .15, .20, .25,.30,.35,.40,.45,.50,.55,.60,.65,.70,.75,.80,.85,.90,.95)), CLEARPOND$Colthearts_N, mean)
which returns the following error:
Error in tapply(quantile(CLEARPOND$word_frequency, probs = c(0.5, 0.1, : arguments must have same length
Is there anyway to fix this/ do this in a more logical way?
I basically want to divide the variable word_frequency into bins of 5% increments. And then find the mean of Colthearts_N for each of those bins. I would also ideally like to plot this on a scatter plot.
My percentiles for word_frequency are as follows:
5% 10% 15% 20% 25% 30% 35% 40% 45% 50% 55% 60% 65% 70% 75% 80% 85%
90% 95% 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 3 4 6 11
Any help would be appreciated
I invented data to test the solution; I believe it achieves your goal
set.seed(42)
CLEARPOND <- data.frame(
word_frequency = rnorm(1000),
Colthearts_N = sample(1:100,
size = 1000, replace = TRUE
)
) %>% arrange(
word_frequency
)
mutate(CLEARPOND,
bin = cut(
x = word_frequency,
breaks = c(
-Inf, quantile(word_frequency,
probs = seq(from = 0.05, to = .95, by = .05)
),
Inf
)
)
) |>
group_by(bin) |>
summarise(avg = mean(Colthearts_N),
n= n())

How to increase two values to match a ratio of 17:8 in Google Sheets

If I have two values with a calculated ratio for example:
Value 1 = 5000
Value 2 = 100
Calculated Ratio = 50:1
How do I distribute a value of 500 between value 1 and value 2 so I can get to a 17:8 ratio or as close as possible to 17:8 ratio without decreasing any of the values.
I tried adding all the values and then splitting them into 17:8 ratio but this will in some cases decrease one value to get to another.
Incorrect example as value one has decreased from its original value of 5000:
Value 1 = 3808
Value 2 = 1792
Calculated Ratio = 17:8
You have two equations and two unknowns. The two unknowns are the adjustment values a and b such as the ratio below is known (17/8)
aspect = (value1+a)/(value2+b)
but the combined value of the adjustments has to be a fixed amount (500)
sum = a + b
Soution 1
The solution if the aspect ratio is float type value 17/8=2.125, then the solution is
a = (aspect*(value2+sum) - value1)/(aspect+1)
b = (value1 - aspect*value2+sum)/(aspect+1)
In your case I get a = -1192 and b = 1692 for
value1 + a = 3808
value2 + b = 1792
The ratio 3808/1792 = 17/8 and the sum (1692) + (-1192) = 500
Solution 2
The solution if the aspect ratio is a rational number aspect = num/den is:
a = (num*(value2+sum) - den*value1)/(den + num)
b = (den*(value1+sum) - num*value2)/(den + num)
and again the sample calculation is (num=17, den=8)
a = (17*(100+500) - 8*5000)/(8 + 17) = -1192
b = (8*(5000+500) - 17*100)/(8 + 17) = +1692
Adjustments
If you constrain a>=0 and a<=sum as well as b>=0 and b<=sum then you would not reach the aspect ratio.
You can do this will the following code adjusting a and b
if (a<0)
{
a = 0;
b = sum;
}
else if(b<0)
{
a = sum;
b = 0;
}
Graph
Graphically this problem is a follows:
The blue line is the combination of Value 1 and Value 2 that have the aspect ratio desired.
The pink dot is the starting value (5000,100).
The slanted lines are the adjusted Value 1 and Value 2 for a given sum amount to adjust by. I have included lines for 500, 1000, 2000, and 4000.
Where the slanted lines intersect the blue line is the ideal solution. The solution
The red dot is where the above solution(s) lead you before adjustments. After adjusting for non-negative a and b you will end up at the black dot.
In google sheets, you need some extra columns to implement the above
This is not specific to sheets and is a basic math cross multiplication problem
So, 17 is to 8 as 500 is to x
17/8 = 500/x
Cross multiplying give us
8 * 500 = 4,000
17 * x = 17x
solving for x
x = 4,000/17
x = 235.29
This was a really fun problem thanks for sharing it. Solution
Spoiler alert! The integers are 5302 and 298 with a final ratio of 17.79 which can be found in row 303.
Edit 1:
I misunderstood the question. A 17:8 ratio can be simplified to 2.125:1. The spreadsheet lists all of the possible combinations, where the smallest ratio is 8.35:1. Thus it doesn't seem there is a solution close to a 17:8 ratio.

determine box size needed

I am trying to calculate the size a big rectangle needed to pack smaller ones.he smaller rectangle have fixed know size and the big rectangle have a fixed width.
In the image, 6 rectangle can fit the big rectangle in which the initial w and height h1 . Now if give more small rectangle, how do i determine the height h2, h3, h4.
i initially went the bin packing route, but this didnt really help as it mainly focused on how many smaller rectangle can fit a big one, but i need instead how much size (height) is needed to fit a certain quantity of smaller boxes.
How do i find the heights h2, h3, and h4.
w = width of original rectangle
h1 = height of original rectangle
w and h1 is given say 300, 400
bh = small rectangles height
bw = small rectangles width
bh and bw is the same for all the rectangles and is given say 40, 40
sb = number of small boxes
three different sets are provided in this example, for each set the required height of the box needed to hold the small rectangles needs to be calculated
for the first set which has sb as 6, I need to find h2
for the second set which has sb as 7, I need to find h4
for the third set which has sb as 8, I need to find h3
It`s still a bit unclear to me. But here is a try to answer your question.
The number of boxes that fit in a single row is:
boxesInRow = floor(w / bw)
In order to fit n boxes, you need the following count of rows:
rows = ceil(n / boxesInRow)
And the height of this big box is then just:
height = rows * bh
Now comes the part where I am not sure. You say that sb is the number of boxes. However, for the first image (h2), you say that sb should be 6, but I count 9 boxes. So apparently, you ignore the first row. If this is really the case, the final formula is:
height = bh * (rows + 1)
= bh * (ceil(sb / floor(w / bw)) + 1)

Maintain the same average value while respecting ratios

I have such a problem on hand. Imagine there are 5 sliders with a range of values 0 to 100. In the beginning, they are all set to 50, so the average score is 50.
Goal 1. Maintain average at 50
Say, if I move the first slider to 70, in order to maintain the average at 50, I decrease the value of the other 4 sliders to 45, i.e. 50 - (20/4) = 45.
Goal 2. Maintain ratios between individual values
The above example was easy, because all 4 affected values where equal. However, if I decide to move the 5th slider to 50, I want all the other sliders to adjust so that the ratios between individual values (e.g. slider 1 / slider 2 is 70 / 45 -> 1,5555...) remain the same.
Here's the method I'm considering.
Step 1. Find the smallest value in the array of affected values (slider 1-4).
Step 2. Calculate ratios of each slider with the minimum-value-slider.
Step 3. This gives me a formula avg(ratio1*minV + ratio2*minV + ratio3*minV + *minV + newManualV) = 50
Step 4. Calculate minV and the remaining values using ratios.
So, in my example, it would be something like this:
newManualV = 50 (5th slider)
minV = 45 (any of the 2nd-4th sliders; let's say it's the 2nd)
ratio1 = 1.55556 (1st and minV)
ratio2 = 1 (3rd and minV)
ratio3 = 1 (3rd and minV)
(1.55556*minV + 1*minV + 1*minV + minV + 50) / 5 = 50
4.55556minV = 200
minV = 43.9
New (rounded) slider values are:
68 (43.9 * 1.55556)
44
44
44
50
Question. Is there a better way of doing this?
What is better? I think there is an easier way, as you do not need to explicitly calculate the ratio's. Just distribute the difference of the altered slider equally.
Denote the slide values with s1, ..., s5.
Suppose you change s1 with and amount d. Then, calculate s, the sum of the other sliders: s = s2+s3+s4+s5. Now, s2 -= (s2/s)*d.
The sum of s1 to s5 does not change (and so the average), and all other sliders are changed in proportion.
Five sliders equals 4 ratios to maintain. For example x_1/x_2. This is done only by multiplying all the slider by the same factor.
As soon as you set one value (for example slider #5) then all the others have to scale accordingly to maintain the ratios.
old_x_5 = x_5
x_5 = (new value)
scale = x_5/old_x_5
x_4 = x_4*scale
x_3 = x_3*scale
x_2 = x_2*scale
x_1 = x_1*scale
Now you have to re-scale everything in order to meet the average goal
average = (x_1+x_2+x_3+x_4+x_5)/5
if average>0
scale = 50/average
x_5 = x_5*scale
x_4 = x_4*scale
x_3 = x_3*scale
x_2 = x_2*scale
x_1 = x_1*scale
else
(now what?)
This changes the new x_5 to a value needed for the average goal instead of the user input. Also what happens if any of the sliders need to be over 100 to maintain the average.

Math Problem With Percentages [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
i'm terrible at math. trust me, you math experts will see why after reading my question.
i have an object that is 300px in height. i need to calculate the percentage of that height where 90% = 300px (or the full height), 45% = 150px, 0% = 0px. so essentially, if i ask for 45% of the object's height, it will return 150px, or if i ask for 32% of the object's height, it will return ____?
i believe this is really basic math, so i apologize in advance.
300 / 90 = 3.3333 px (= 1%)
32 * 3.3333 = 106.56
If 90% of it is 300, 100% of it is:
100/90 * 300 = 333.33
Change the 100 to whatever else to get other percentages.
45/90 * 300 = 150
32/90 * 300 = 106.67
(45 / 90) * 300 = 150px
(32 / 90) * 300 = ~106px
Are you asking how to calculate percentages?
300 * .90 = 270
270 is 90% of 300.
Is that what you're after?
Or are you after the original percentage?
If you know 150 is 45% of X, then
X = 150 / .45
Result: 333
You can't have two different proportions of something have the same value.
If 100% is 300px and 90% is the same, then you're using some ranges where the size is the same. The question is what's the range size, so you can see in what range you 32% is.
pixels = percentage * constant
In your case is constant = 300/90 = 10/3 = 3.333
45% 150
100% x
x = (150 * 100) / 45 = 333.33
100% is 333.33 so 32% is 333.33 * 0.32 = 106.67
Your Answer = 106.66
If you compute how much 90% of an objects height is, you do it like:
height * 0.9 = something
something in your case, was 300, thus we have
height * 0.9 = 300
by dividing both sides with 0.9 we now get:
height = 300 / 0.9 = 333.33...
thus the answer is that the "original"/100% height of the object is 333.33... pixels.

Resources