BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lawongd
Calcite | Level 5

 

I will like to write a code for values of x = (-0.1, 0.0, 0.1)

 write code to calculate L (x ; mu = 0, sigma = 1)

 

In R code(L <-function(x, u=0, s2=1)(sqrt(2*pi*s2))^-1*exp(-(x-u)^2/(2*s2))
x<-c(-0.1,0.0, 0.1)
L(-0.1)

L(0.0)

L(0.1)

 

Also using 

dnorm(-0.1, mean = 0, sd = 1)
dnorm(0.0, mean = 0, sd = 1)
dnorm(0.1, mean = 0, sd = 1)

dnorm(c(-0.1,0.0,0.1),mean = 0, sd = 1)

 

yield as results in R. 

[1] 0.396952547477
[1] 0.398942280401
[1] 0.396952547477


[1] 0.396952547477 0.398942280401 0.396952547477

 

I want to write equations in either IML or Macro language

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
proc iml;
   do x=-0.1 to 0.1 by 0.1;
      y=pdf('normal', x, 0, 1);
      print y;
   end;
quit;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
proc iml;
   do x=-0.1 to 0.1 by 0.1;
      y=pdf('normal', x, 0, 1);
      print y;
   end;
quit;
Lawongd
Calcite | Level 5

Thanks alot for you helps. The code

 

proc iml;
   do x=-0.1 to 0.1 by 0.1;
      y=pdf('normal', x, 0, 1);
      print y;
   end;
quit;

 

is similar to using dnorm in R right?

 

 

can I also write in IML or macro language the code below? 

 

In R code(L <-function(x, u=0, s2=1)(sqrt(2*pi*s2))^-1*exp(-(x-u)^2/(2*s2))
x<-c(-0.1,0.0, 0.1)
L(-0.1)

L(0.0)

L(0.1)

 

Thanks alot

 

Ksharp
Super User

Sure. You can. Define a function in IML and @Rick_SAS  wrote many blogs about it. and Post it at IML forum since it is a IML question.