Hi, I have the following data:
- A vector of physical stimulus properties, something like: [0.8, 0.7, 0.56,0.4,....,0.01]
- For each of the vector's elements, the response of the subject (either "0" or "1").
What I want: I want to bin the data with the physical stimuli, and determine the percentage of "1"s responded for this bin (it would be the percentage of correct answers for the bin).
Additionally, I want a curve fittet through these percentages. I know about the hist function, but I am not sure of how I can apply it here. Thanks

1 comentario

Farooq Muhammad
Farooq Muhammad el 17 de Mzo. de 2022
hi all
i want the answer to simulation question.
i have the error plot of height above the sea level w.r.t to some reference system.
i want to bin the x axis and curve fit the bins using curve fitting tool or something else to know how error is behaving w.r.t height above the sea level.
help requierd.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Jun. de 2017

1 voto

binedges = 0 : 0.1 : 1; %set as appropriate
[~, ~, binnumber] = histcounts( StimulusVector, binedges );
maxbin = max(binnumber);
count0 = accumarray(binnumber, Response == '0', [1 maxbin]);
count1 = accumarray(binnumber, Response == '1', [1 maxbin]);
total_for_bins = count0 + count1;
percent_per_bin = count1 ./ max(1,total_for_bins) * 100;
If you only need the percentages and not the counts, you can make this a bit shorter:
binedges = 0 : 0.1 : 1; %set as appropriate
[~, ~, binnumber] = histcounts( StimulusVector, binedges );
percent_per_bin = accumarray(binnumber, Response == '1', [], @mean) * 100;
To fit a curve:
x = (binedges(1:end-1) + binedges(2:end))/2;
y = percent_per_bin;
and now you can fit your curve on x and y using whatever distribution seems suitable. You might want to look inside histfit() to see how it does the fitting and plotting.

7 comentarios

MiauMiau
MiauMiau el 20 de Jun. de 2017
Thanks! But I get the following error for my implementation:
% my variables
ThumbArray=[0.07,0.0805,0.068425,0.05816125,0.0494370625,0.042,0.0357182776562500,0.0303605360078125,0.0258064556066406,0.0219354872656445];
responseThumb=[3,1,1,1,1,1,1,1,1,1];
binedges = 0 : 0.01 : max(ThumbArray); %set as appropriate
[~, ~, binnumber] = histcounts( ThumbArray, binedges );
percent_per_bin = accumarray(binnumber, responseThumb == '1', [], @mean) * 100;
%Curve fitting:
x = (binedges(1:end-1) + binedges(2:end))/2;
y = percent_per_bin;
Error:
Error using accumarray
Second input VAL must be a vector with one element for each row in SUBS, or
a scalar.
Error in fitStaircase (line 14)
percent_per_bin = accumarray(binnumber, responseThumb == '1', [], @mean) *
100;
What does that mean..?
Walter Roberson
Walter Roberson el 20 de Jun. de 2017
percent_per_bin = accumarray(binnumber, responseThumb(:) == '1', [], @mean) * 100;
MiauMiau
MiauMiau el 20 de Jun. de 2017
Hm, this gives me the exact same error unfortunately
Walter Roberson
Walter Roberson el 20 de Jun. de 2017
You could try
percent_per_bin = accumarray(binnumber(:), responseThumb(:) == '1', [], @mean) * 100;
MiauMiau
MiauMiau el 20 de Jun. de 2017
thank you. I changed the maximum of binedges:
responseThumb = response(finger==1);
binedges = 0 : 0.01 : max(ThumbArray)+0.01; %set as appropriate
[~, ~, binnumber] = histcounts( ThumbArray, binedges );
percent_per_bin = accumarray(binnumber(:), responseThumb(:) == '1', [], @mean) * 100;
%To fit a curve:
x = (binedges(1:end-1) + binedges(2:end))/2;
y = percent_per_bin;
And it is not throwing an error - however, y is a zero-vector. Why is that?
Walter Roberson
Walter Roberson el 20 de Jun. de 2017
You wrote that the response is (either "0" or "1") so my interpretation is that the responses are the characters '0' or '1' . If they are instead the numeric values 0 or 1 then change the '1' in the code to plain 1
MiauMiau
MiauMiau el 22 de Jun. de 2017
thx!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Preprocessing en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Jun. de 2017

Comentada:

el 17 de Mzo. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by