Reputation: 939
I wrote the following code to plot the Logit function where beta = 1.
beta = 1
e(:,1) = 0:0.01:1;
e(:,2) = log(e(:,1)./(1-e(:,1)))+beta;
plot(e(:,2),e(:,1))
As far as I can tell that looks fine, but I don't know how to add the Probit function. I understand how to put to plots in one figure, but I don't understand how to generate data from this distribution. Is there some convenient way to do this in MATLAB?
Ultimately I'm looking to create something like the following, in which it can be seen that the Probit and Logit are very similar.
Upvotes: 2
Views: 1146
Reputation: 1456
beta = 1
e(:,1) = 0:0.01:1;
e(:,2) = log(e(:,1)./(1-e(:,1)))+beta; % logit fn + beta
e(:,3) = sqrt(2) * erfinv(2*e(:,1) - 1) ; % probit fn
plot(e(:,1),e(:,2:3))
As suggested by @patrick if you have the "Machine learning and statistic toolbox" it would be cleaner to use the norminv
function, that is replace the 4th line by:
e(:,3) = norminv(e(:,1)) ; % probit fn
Upvotes: 3