The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

"R Script"

PowerfoolPowerfool Member Posts: 2 Contributor I
edited June 2019 in Help
Can any body help with writing R Scripts?
I have RM v.5.3.005 and R v.2.15.2

Tried to use "Execute Script (R)" operator with this code (kernel regression estimator):

x<-input[1]
y<-input[2]

H <- function(z) {
if (abs(z)<=1)
return((cos(pi*z)+1)/2)
else
return(0)
}

ys <- function(t,x,y,cs) {
m <- length(t)
n <- length(x)
K <- c(1)
result <- c(1)
for (i in 1:m)
{
for (j in 1:n)
K <- H((x-t)/cs)
denominator <- sum(K)
if (denominator==0)
result <- 0
else
{
numerator <-0
for (j in 1:n)
{numerator <- numerator + y*K}
result <- numerator/denominator
}
}
return (result)
}

output<-c(x,y,ys(x,x,y,0.5))

I ran process and got nothing as a result. Reading log got this line:
Feb 16, 2013 12:59:07 PM INFO: Execute Script (R): 1: package 'mlr' is not available (for R version 2.15.2)
So i believe that might be the problem

P.S. Executing the same code in RM's R console everything is OK.
Tagged:

Answers

  • PowerfoolPowerfool Member Posts: 2 Contributor I
    Right, so I've found the solution myself. For those who got the same trouble:
    I've read some threads about similar problems and changed my code into this:

    x<-Data$a1
    y<-Data$a2


    H <- function(z) {
      if (abs(z)<=1)
          return((cos(pi*z)+1)/2)
      else
          return(0)
    }

    ys <- function(t,x,y,cs) {
    m <- length(t)
    n <- length(x)
    K <- c(1)
    result <- c(1)
    for (i in 1:m)
    {
    for (j in 1:n)
    K <- H((x-t)/cs)
    denominator <- sum(K)
    if (denominator==0)
    result <- 0
    else
    {
    numerator <-0
    for (j in 1:n)
    {numerator <- numerator + y*K}
    result <- numerator/denominator
    }
    }
    return (result)
    }

    output<-data.frame(x,y,ys(x,x,y,0.5))

    Good luck and "make love not war"!!! ;D
Sign In or Register to comment.