elaine20:~> mkdir s208 elaine20:~> cd s208Make a file called standnorm.m with the following lines:
function out=standnorm(n) out=randn(1,n);
If you are working on a leland machine, you could also simply copy the file from the course directory:
cp /usr/class/stat208/lab/standnorm.m .
elaine20:~> matlabYou should see the matlab prompt:
>>
>> standnorm(15) ans = Columns 1 through 5 -0.4326 -1.6656 0.1253 0.2877 -1.1465 Columns 6 through 10 1.1909 1.1892 -0.0376 0.3273 0.1746 Columns 10 through 15 -0.1867 0.7258 -0.5883 2.1832 -0.1364
>> sampling=mean(standnorm(15)) sampling = 0.2158sampling is the mean of a sample of size 15.
Next, (1)
>> sampling=[sampling mean(standnorm(15))] sampling = 0.2158 -0.1201What does this command do?
Now repeat the previous command 10 more times. Stop when you see sampling is a vector of length 12. (hint: your key
may save you a lot of typing in matlab).
How could we get the mean and variance of the medians of 100 samples of
size 15?
If we want to discard the sampling vector we have so far, we could do:
>> sampling=zeros(0); >> for i=1:100 sampling=[sampling median(standnorm(15))]; end
>> sampling=zeros(100,1); >> for i=1:100 sampling(i)=median(standnorm(15)); end
>> start=cputime; ... >> ending = cputime-start;
hint: Use the help command in Matlab.
You can download a pdf file of this lab here.
Make a file called myrand.m with the following lines:
function out=myrand(m,n,range) %Returns a vector of draws %of integers from 1 to n, %with replacement out=floor(rand(m,n)*range)+1;
Make a file called bsample.m with the following lines:
function out=bsample(orig) %Function to create one resample from %the original sample orig, where %orig is the original data, and is a %matrix with nrow observations and ncol variables [n,p]=size(orig); indices=myrand(1,n,n); out=orig(indices,:);
Make a file containing the complete 82 point law school data by downloading it from the class web directory, http://www.stanford.edu/class/stats208/law82. You can use save as in the netscape file option. Or you can copy the file law82 from the /usr/class/stats208/lab/ directory.
Start Matlab. Matlab is installed on all leland machines -
elaine, tree, etc.
You should see the matlab prompt:
»
Then type format compact to get more on your screen.
Using the randtool, generate two poisson data of size 1000, one with parameter , one with parameter . To do that type randtool at the matlab prompt. Adjust the name of the distribution, the parameter value and the size of the dataset. To save data you generated using randtool, click on Output. Save data sets as Poisson1 and Poisson2. Return to Matlab and answer the following questions:
load law82