All 3 entries tagged Matlab
View all 7 entries tagged Matlab on Warwick Blogs | View entries tagged Matlab at Technorati | There are no images tagged Matlab on this blog
September 22, 2010
Where did all that time go!
In about a week's time, I'll be flying back to the UK!
Almost time to submit report and poster. Second draft of report is finished, poster is unfinished yet. Hoping to get everything done by next Monday.
Of course, I made a rather good prediction - with the CSC resources going offline far too often in the past month, I've just barely managed to scrape by with the simulations I need. I've even resorted to running some on my 5 year old desktop at home!
Note to self: Think further ahead when running simulations - get the parameters right! I now have data which are not very compatible with each other, sigh. Wouldn't be that bad if I had the resources to get my simulations re-run quickly!
---------------------------------------------
Turns out after I posted the last entry I had the chance to speak to a friend who's working with the Singapore Land Transport Agency (LTA), and so I had a chance to ask him about Distance-based fares.
"So, how did you guys come up with the 66% figure? Based on real data?"
"Yes, that's right."
"Hmm, alright. Is it also true then that the fare decreases are mostly less than 10 cents while the increases are mostly greater than 10 cents?"
"Hmm, yes, you could say that."
"So there's an overall increase in revenue?"
"Yes."
Before anyone misunderstands, I'm not criticising the increase in revenue, after all, inflation is (somewhat) a part of life. I just wish to point out how a figure being thrown about can be rather meaningless, in this case the two-thirds having lower fares being repeatedly mentioned. I have no access to the real data to verify if it is true in any case. (Britons, rejoice that you actually have the Freedom of Information Act!)
In any case, I've done my fair bit in abusing the new fare system. I had to take a bus ride back home, where I was faced with the option of getting off and walking 7 minutes home or changing to a feeder bus service right to my doorstep. Under the old fare system, the latter would cost me an extra 25 cents. It cost me only 8 cents now.
August 05, 2010
Simple simulation – Am I being naive?
Saw this sometime last week: http://bengoldacre.posterous.com/i-think-this-guardian-story-is-a-bit-wrong
I will not rehash the main points, but the idea that popped up in my mind was, the patients will not necessarily all have the same mortality rate so what happens if we have a population of patients with different mortality rates?
I thought of possible ways to simulate this, but did not sit down to try it till today. Took me a while to figure out the relevant MATLAB commands and to structure it. Thanks goes to Leonard who gave me some ideas on how to write the code.
Simple assumptions of population of patients:
- 10% have 6% mortality rate (difficult case)
- 25% have 3% mortality rate (moderate case)
- 65% have 1% mortality rate (simple case)
And then each hospital has a certain number of patients, which is fixed. How do the hospitals do?
For size 5:
Value Count Percent
0 2653 26.53%
1 5081 50.81%
2 1946 19.46%
3 301 3.01%
4 19 0.19%
For size 10:
Value Count Percent
0 541 5.41%
1 2118 21.18%
2 3224 32.24%
3 2488 24.88%
4 1188 11.88%
5 370 3.70%
6 67 0.67%
7 4 0.04%
I did 10000 realizations on both.
Would it be fair then to say that a hospital with low number of patients can easily get a high mortality rate by just being unlucky?
MATLAB code for those interested below. I may have missed out something as I finished this in less than an hour!
-------------------------------------------------------------------------------
function AAAsim(nRlz,sz)
% Simulation of AAA patients.
% Assume 2% mortality in general
% 3 Classes of Patients:
% 10% chance of patient with 6% mortality
% 25% chance of patient with 3% mortality
% 65% chance of patient with 1% mortality
%
% Assume each hospital has sz patients
n = nRlz * sz; %population size
index = randperm(n); % Randomly order patients
for i=1:nRlz
a = sz*(nRlz - 1) + 1;
b = sz*(nRlz);
sample = index(a:b);
sam_death = 0;
for j=1:sz
pt = sample(j);
if(pt <=(0.1*n));
prob = 0.6;
elseif(pt > (0.1*n) && pt <=(0.35*n));
prob = 0.3;
else(pt > (0.35*n));
prob = 0.1;
end
prob;
ptdoa = binornd(1,prob); % Returns 0 if alive, 1 if dead
sam_death = sam_death + ptdoa;
end
deaths(i)= sam_death;
fprintf('Iteration number %d completed.\n',i);
end
tabulate(deaths)
hist(deaths,0:sz)
July 13, 2010
Linux tips and tricks
From Dr Nichols on script files:
Make a script file, .sh
test.sh
must begin "#!/bin/bash"
Give it execute permissions
chmod +x test.sh (Important! If not script will not run!)
and be sure to re-direct all output to a log file
Then when you run the script, put it in the background
./test.sh &
Here is my test.sh file
#!/bin/bash
matlab -nojvm -nodisplay < doit.m > test2.log 2>&1
Also, how to start up matlab and add path to matlab every login
Edit ./.bashrc, using say, emacs i.e. at the prompt type "emacs ./.bashrc"
Add the following lines:
module add matlab
export MATLABPATH=$MATLABPATH:$HOME/spm8/
for example, given that I put the spm8 files into /home/spm8/
Useful commands to view log files are cat, tail etc.