Symbolic operations in the R

Asked

Viewed 51 times

2

I need to multiply two matrices in the R, one has symbolic entries (beta) and the other is a numerical matrix (X), I’ve tried the packages Ryacas and rSymPy, but I couldn’t make it work. After that, I need to derive the function f in relation to beta0 and then in relation to beta1. below is the code:

library(Deriv)
library(Ryacas)
#library(rSymPy)
n=2
#Vetor de 1's
const1 <- rep(1,n);
const <- cbind(const1);
#Vetor de cováriavel com distribuição unif(0,1)
X1=matrix(runif(n, 0, 1),nrow=n,ncol=1)
#Matriz de covariáveis
X <-matrix(c(const,X1),nrow=n,ncol=ncol(X1)+1)
p=ncol(X)
beta0 <- Sym("beta0")
beta1 <- Sym("beta1")
alpha <- Sym("alpha")
y <- Sym("y")
beta=matrix(c(beta0,beta1),nrow=2,ncol=1)
mu1=exp(X%*%beta)
f <- quote(mu1*y^2+mu1*alpha)
f1 <- Deriv(f,"beta0")
f2 <- Deriv(f,"beta1")

Does anyone have any suggestions as to how I can proceed with these calculations?

  • 1

    I’ve never worked with these packages or with symbolic values, much less Yacas, but from what I’ve seen you won’t be able to turn an array into a Sym object, because it should always be length 1. To create matrices, there seems to be a specific notation. I suggest you read the manual and the Vignette package.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.