Page 1 of 1
RATS procedures: loop and dec function
Posted: Sat Jun 18, 2016 6:30 pm
by apple
This may be a very basic question but I wish create a 100x1 vector (I name it "temp") that has the values of draws from standard normal distribution using a loop. Here is an attempt that I made but I am not sure if I am declaring the correct type to start with. Further, how do I compute the average and standard deviation of "temp" and show these statistics in the output window?
dec vect temp(100)
do i = 1,100
compute temp(i) = %ran(1)
end do i
%mean(temp)
%sqrt(%variance(temp))
Re: RATS procedures: loop and dec function
Posted: Sat Jun 18, 2016 9:45 pm
by TomDoan
You don't have to do a loop---
%ran will apply to all elements of a vector.
You need a
DISPLAY instruction to show the information.
dec vect temp(100)
compute temp=%ran(1.0)
disp %mean(temp)
disp sqrt(%variance(temp))
Re: RATS procedures: loop and dec function
Posted: Sun Jun 19, 2016 11:18 pm
by apple
Thank you for your reply. I have run the above code and obtained the following error "## Unassigned 117 >>>>disp %mean(<<<<" Could you kindly tell me what this error means? Thanks.
Re: RATS procedures: loop and dec function
Posted: Mon Jun 20, 2016 7:47 am
by TomDoan
Is there a reason you want a VECTOR rather than a SERIES?
set temp 1 100 = %ran(1.0)
stats temp
would give you the mean, variance and and more. For computing those for a VECTOR, you would use %AVG(temp) to compute the mean and %COV(temp,temp) to compute the variance.