How to transform data to have new minimum, maximum and average values?
Show older comments
Hi all,
I have the following dataset with min = -6.3, max = 1.0 and mean = -3.3. Is there an easy way in matlab to transform these data to have a new minimum (-8.0), maximum (1.5) and mean (-2.9)? Thanks!
-5.0
-6.3
-4.6
-2.4
0.3
1.0
-4.7
-4.9
4 Comments
Walter Roberson
on 26 Sep 2022
it would have to be a nonlinear transform
rescale will rescale to given range, but the mean will be whatever it turns out to be...as Walter says, you can't do all three with a linear transformation.
x=[-5.0
-6.3
-4.6
-2.4
0.3
1.0
-4.7
-4.9];
mean(rescale(x,-8,1.5))
That's going to have to be skewed pretty strongly to move the mean that much with so few observations...
Nadia Shaik
on 12 Oct 2022
Edited: Nadia Shaik
on 12 Oct 2022
Hi Yoni,
To help me understand your query better, the following information is required:
- Sample Input
- Expected Ouput
This is really an unreasonable request when look at the input data at all...the original have a range from
Original Desired Difference
min = -6.3 -8.0 -1.7
max = 1.0 1.5 +0.5
mean= -3.3 -2.9 +1.4
It is expected to move the mean up by >1 while moving the minimum down by over 3X the amount of the adjustment upward on the high end. Just ain't agonna happen w/o a very strongly biased redistribution of the individual elements in the vector.
One would have to have something like a reverse Box-Cox transformation from more to less normal. It's surely possible could be made to happen, but just seems misguided.
That the OP never came back is somewhat telling it would seem, also.
x=[-5.0 -6.3 -4.6 -2.4 0.3 1.0 -4.7 -4.9];
subplot(3,1,1)
histfit(x)
subplot(3,1,2), hist(x), xlim([-8 2])
subplot(3,1,3), hist(rescale(x,-8,1.5))
The normality plot doesn't look so bad, but that's owing to the minimal number of points and the coarse binning; the actual distribution is pretty much at the ends alone...
Accepted Answer
More Answers (1)
Nadia Shaik
on 11 Oct 2022
Hi Yoni,
I understand that you want to transform existing data to have new minimum, maximum and mean values.
The minimum, maximum and mean values can be altered in an iterative way.
The following code snippet illustrates how to alter the parameters.
new_mean = 6;
new_min = -2;
new_max = 9;
error = 0.01;
x= [-5.0 -6.3 -4.6 -2.4 0.3 1.0 -4.7 -4.9];
while abs(new_mean - mean(x)) >= error
if new_mean > mean(x)
x(find(x < new_mean,1)) = randi([new_mean new_max]);
elseif new_mean < mean(x)
x(find(x > new_mean,1)) = randi([new_min new_mean]);
end
end
The above code will work accurately for large array sizes.
I hope this helps.
1 Comment
dpb
on 11 Oct 2022
That isn't a tranformation of the original dataset as asked for but the generation of a new dataset.
That may be ok, but is answer to a different Q? than the one posed by OP.
Categories
Find more on F Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
