Is there a way of classifying a set of curves into two or three groups? - hypothesis-test

I conducted an experiment, in which participants (n=44) experienced different tones ranging from low to high (x-axis) and rated their perceived liking from 1- low to 10 - high(y-axis).
I created line charts for each participant. Just by looking at them, I think the resulting curves could be grouped into two to three groups. The first group only shows one major change in the perception during the experiment:
The second group shows a gradual development, which takes place over three to four tones and continues up to the lowest tone presented
.
The third group also shows a gradual development, but the development stabilizes :
However the observed change does not always happen at the tone "4", but the pattern of the curve can still be matched to one of the three groups.
I would now like to back that "visual" assessment up by performing a statistical test or classification. However, I do not know, which method would be suitable for my question.
Are there any suggestions, what method or test can be performed to assess (i) how many groups can be derived and (ii) which participants than can be assigned to which group?
Data sample:
Group 1:
n1 = 10, 10, 10, 10, 6, 6, 6
n2 = 10, 10, 10, 10, 5, 5, 5
n3 = 10, 10, 10, 10, 5, 5, 5
n4 = 10, 10, 10, 6, 6, 6, 6
n5 = 10, 10, 10, 5, 5, 5, 5
Group 2:
n1 = 10, 10, 10, 7, 6, 4, 2
n2 = 10, 10, 10, 8, 6, 4, 3
n3 = 10, 10, 8, 7, 5, 4, 3
n4 = 10, 10, 10, 8, 6, 4, 3
n5 = 10, 10, 10, 8, 5, 4, 2
Group 3:
n1 = 10, 10, 10, 10, 8, 6, 6
n2 = 10, 10, 10, 10, 7, 5, 5
n3 = 10, 10, 10, 8, 5, 5, 5
n4 = 10, 10, 10, 8, 4, 4, 4
n5 = 10, 10, 10, 7, 5, 5, 5

Related

Why can SVD predict the score?

Why can SVD predict the score? I now have a matrix A, and then I know the specific values of the second row and the fourth column of matrix A
A = array([[5, 5, 3, 0, 5, 5],
[5, 0, 4, 0, 4, 4],
[0, 3, 0, 5, 4, 5],
[5, 4, 3, 3, 5, 5]]
)
The matrix decomposition is like this, but its second row and fourth column is -0.6417. Can this value also be used as the prediction result?
[[ 5.28849366 3.27680993 3.53241833 1.14752376 5.07268712 5.10856603]
[ 5.16272816 1.90208542 3.54790449 -0.64171367 3.6639954 3.40187912]
[ 0.21491233 3.74001967 -0.13316888 4.94723591 3.78868964 4.61660489]
[ 4.45908022 3.80580974 2.8984041 2.38455041 5.31300379 5.58222367]]

Matlabs xcorr function in c

I am using the function
in = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
lag = 8;
out = xcorr(in, lag)
it produces the output:
out = [175,000000000000, 238,000000000000, 308, 384, 465, 550, 638, 728, 819, 728, 638, 550, 465, 384, 308, 238, 175,000000000000];
I do not understand from Matlabs documentation how to get those values. Is there any kind of formula that I can use for that?
In general matlab documentation put the formulas in a chapter named More about, look at this chapter to understand which formula matlab implements.
This is the link to the More about chapter of the xcorr function.
https://it.mathworks.com/help/signal/ref/xcorr.html#bubr0h6
For greater clarity look at this code:
in = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
lag = 8;
N = length(in);
correlation = zeros(2*lag,1);
for m = -8:8
correlation(m+8+1) = sum(in.*[zeros(1,abs(m)) in(1:N-abs(m))]);
end
where sum(in.*[zeros(1,abs(m)) in(1:N-abs(m))]); computes the sum of the product beetween in and its shifted version. To compute the shifted version of in simply padding the first m elements with zero and the N-m element are in(1:N-m). I've used the abs because the lag m is either negative or positive.
Try the code and also print [zeros(1,abs(m)) in(1:N-abs(m))] for various value of m to understand better how look the shifted version of the vector.
For homework: why we use [zeros(1,abs(m)) in(1:N-abs(m))] and not [zeros(1,abs(m)) in(1:N)]?
P.s in this case you are calculating the autocorrelation, so the y vector is x.
For more details about the theory check the Reference chapter to see which books matlab refers.

Why does Qhull error when computing convex hull of a few points?

I'm trying to compute the convex hull of 9 points in 10 dimensional space. Through the scipy interface, I'm calling scipy.spatial.ConvexHull(points) and getting QH6214 qhull input error: not enough points(9) to construct initial simplex (need 12)
I think the definition of convex hull is well defined regardless of the dimension. What is going on here? Is there a different function I can call that might fix this?
Maybe projecting the points on a hyperplane before computing the hull will do the trick.
Use for example the Principal Component Analysis class sklearn.decomposition.PCA from the scikit-learn toolkit, to reduce dimension.
vertices = np.random.randn(9, 10)
from sklearn.decomposition import PCA
model = PCA(n_components=8).fit(vertices)
You can now transform back and forth from your vertices to the projected using model.transform and model.inverse_transform.
proj_vertices = model.transform(vertices)
hull_kinda = ConvexHull(proj_vertices)
hull_kinda.simplices
This outputs something like this
array([[6, 4, 3, 8, 0, 7, 5, 1],
[2, 4, 3, 8, 0, 7, 5, 1],
[2, 6, 3, 8, 0, 7, 5, 1],
[2, 6, 4, 8, 0, 7, 5, 1],
[2, 6, 4, 3, 0, 7, 5, 1],
[2, 6, 4, 3, 8, 7, 5, 1],
[2, 6, 4, 3, 8, 0, 5, 1],
[2, 6, 4, 3, 8, 0, 7, 1],
[2, 6, 4, 3, 8, 0, 7, 5]], dtype=int32)
Use now the model.inverse_transform to get the simplices back in your 10 dimensions.

Expand an array by filling in with current values in MATLAB

I have a fairly simple issue and I just want to know if there's an easy way to do it in MATLAB (i.e. a function to do this rather than writing out loops or something myself).
Let's say I have a timeseries where Time is 1:1:1000 and Data is 2 * (1:1:1000) and I want to expand the array by making the Time and Data vector finer. Let's say that I want Time to be 1:0.1:1000 and Data to be 2 * (1:0.1:1000). Is there an easy way to tell MATLAB that to repeat the values of each vector 10 times (from 1 / 0.1 = 10) so that I can have something like this?:
Time: [1, 2, 3, 4, ...]
Data: [2, 4, 6, 8, ...]
to:
Time: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, ...]
Data: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, ...]
You can use combination of reshape() and repmat() as follow:
Data = [2, 4, 6, 8, ...] % As stated in the question.
Data = reshape(repmat(Data, 10, 1), 1, []);
This is more time-efficient than the others like kron() or combination of sort() and repmat().
Two simulations were done and the results are shown in the following figures.
First: Simulation time vs. length of Data. Here I used N=100 instead of 10.
Second: Simulation time vs. repetition factor. Length of Data is 10000.
So you can select the best one according to the simulation results.
As seb proposed, you can use the function repmat. Here what I would do:
Data = [2, 4, 6, 8, ...];
Data = sort(repmat(Data,1,10));
You can use repmat
interval_size = 10;
Data = 2*(1:1:1000);
out_data = repmat(Data,interval_size,1);
out_data = out_data(:)';
Example Data:
time=1:50
data=2:2:100
t2=1:.1:50.9
For time=1:n this is very simple:
data(:,floor(t2))
If your original data has another time scale, use this:
[a,b]=ismember(floor(t2),time)
data(:,b)

How to reshape a vector to make a matrix? [duplicate]

This question already has answers here:
Reshaping of Array in MATLAB
(3 answers)
Closed 7 years ago.
Here is what I have:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
And here is what I want to get:
[
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12
]
The number of rows and columns (3 and 4 in example) is already known.
How would I do that?
reshape
b = reshape(a, 4, 3)' will would work for your example. Elements are taken from the original and inserted into the new matrix column-wise.
Furthermore, reshape is a built-in MATLAB function. There exists other solutions such as vec2mat that require the communications toolbox.
This guide says
mat = vec2mat(vec,matcol) converts the vector vec into a matrix with matcol columns, creating one row at a time. If the length of vec is not a multiple of matcol, then extra zeros are placed in the last row of mat. The matrix mat has ceil(length(vec)/matcol) rows.