# Logarithmic probabilty distribtion and respective problems in matlab

Dear crossvalidated community,

quite frankly, I'm not that much into statistics and therefore, I'm having much trouble solving some issues im having in Matlab right now. My plan is to imitate/simulate some realistic driving patterns of costumer in a car sharing simulator. Therefore, I picked a logarithmic probability distribution that represents/models the desire to rent a car once in a while.

So as of now, I have 500 customer that are devided into three different types of customers with different mean intervals:

if  hourOfDay > 20 || hourOfDay < 9 % night

if obj.custType == 1
meanInterval = 45*24*60;
stDev = meanInterval/10;
MU = log(meanInterval^2 / sqrt(stDev^2+meanInterval^2));
SIGMA = sqrt(log(stDev^2/meanInterval^2 + 1));
obj.minInterval = lognrnd(MU,SIGMA);

elseif obj.custType == 2
meanInterval = 30*24*60;
stDev = meanInterval/8;
MU = log(meanInterval^2 / sqrt(stDev^2+meanInterval^2));
SIGMA = sqrt(log(stDev^2/meanInterval^2 + 1));
obj.minInterval = lognrnd(MU,SIGMA);

elseif obj.custType == 3
meanInterval = 25*24*60;
stDev = meanInterval/9;
MU = log(meanInterval^2 / sqrt(stDev^2+meanInterval^2));
SIGMA = sqrt(log(stDev^2/meanInterval^2 + 1));
obj.minInterval = lognrnd(MU,SIGMA);
end

else %daytime
if obj.custType == 1
meanInterval = 7*24*60;
stDev = meanInterval/5;
MU = log(meanInterval^2 / sqrt(stDev^2+meanInterval^2));
SIGMA = sqrt(log(stDev^2/meanInterval^2 + 1));
obj.minInterval = lognrnd(MU,SIGMA);

elseif obj.custType == 2
meanInterval = 20*24*60;
stDev = meanInterval/9;
MU = log(meanInterval^2 / sqrt(stDev^2+meanInterval^2));
SIGMA = sqrt(log(stDev^2/meanInterval^2 + 1));
obj.minInterval = lognrnd(MU,SIGMA);

elseif obj.custType == 3
meanInterval = 15*24*60;
stDev = meanInterval/9;
MU = log(meanInterval^2 / sqrt(stDev^2+meanInterval^2));
SIGMA = sqrt(log(stDev^2/meanInterval^2 + 1));
obj.minInterval = lognrnd(MU,SIGMA);
end


the "obj.mininterval" is the key factor here (determined by the logarithmic prob. density function) and is used to determine whether they want to drive or not:

hasNotDriven = customers{cc}.minInterval < tt - customers{cc}.lastNightDrive;


(in case that the mininterval is lower than the current time of the simulation minus their last rental, they start driving)

For example in this code, customer type 1 is supposed to drive once a week (plus/minus a little deviation so that it's a more or less random pattern) at daytime and, if it is nighttime, each 45 days.

In order to avoid that all customers start driving immediately after I started the simulation, I randomly defined when they drove the last time (e.g.):

if obj.custType == 1
obj.lastDayDrive = -(4*24*60)*rand(1)*rand(1);
obj.lastNightDrive = -(42.234*24*60)*rand(1)*rand(1);


However, they don't abide by my rules and keep driving and renting cars like it's their sole purpose in life (they drive far more often than just once a week). Have a look at the following image:

the green parts of the figure represent daytime and the black ones nighttime.

I'm well aware that my request is rather confusing but please feel free to ask as much as you require. I mean I clearly defined the mean, so why do I keep having these spikes?! I mean, as you can see it's more like all 500 customers drive once a week although, from the various mean intervals, they should be driving far less often (solely customer type 1 is supposed to drive once a week, the other customer types should drive like once every twenty days or so; thus, I consider the mininterval to be lower than it actually should be).

edit: lowering the standard deviation didn't help either:

• Looking at your code I can't help but wondering whether you meant lognormal distribution rather than logarithmic distribution. – Glen_b Aug 14 '14 at 23:41
• I suppose I did :) However, I found the mistake and it had nothing to do with the choice of distribution. For anyone interested, I'll write an answer! – Atlan Aug 15 '14 at 14:26

hasNotDriven = customers{cc}.minIntervalday < tt - customers{cc}.lastDayDrive;

hasNotDriven = customers{cc}.minIntervalday < ttday - customers{cc}.lastDayDrive;