# Math calculation in assign method

Dear all,

1， is it possible to do matrix calculation in assign method, see below, the X.mat has already defined on server

``````datashield.assign.expr(opals[[1]], symbol = "xtx.mat", quote(t("X.mat")%*%"X.mat"))
``````

2, I am quite confued whether I should use “X.mat” or X.mat as the arguement? Could you explain the logic to pass the parameters of assign or aggregate methods.

Hi,

Unless I am mistaking you are multiplying X.mat (a server variable) with nothing. Also, it is unclear whether X.mat exists on the server.

Best wishes,

P.

Hi Hank,

It is quite tricky to do matrix calculations using the ds.assign or the ds.make functions because some symbols that you want to use might be blocked by the R parser.

However, in DataSHIELD we have a set of functions that can be used for different matrix calculations (e.g. transpose, multiplication, etc). Here is an example:

# generate a vector of length 20 of uniformly distributed data

ds.rUnif(samp.size=20, min=-10, max=10, newobj=“randVector”)

# check that the vector was created correctly

ds.ls()

ds.class(“randVector”)

ds.length(“randVector”)

# create a 4 by 5 matrix using the elements from the created random vector

ds.matrix(mdata=‘randVector’, nrows.scalar=4, ncols.scalar=5, newobj=“X.mat”)

# check that the matrix was created correctly

ds.ls()

ds.class(“X.mat”)

ds.dim(“X.mat”)

# create the transpose of X.mat (the transpose is a 5 by 4 matrix)

ds.matrixTranspose(M1=“X.mat”,newobj=“X.mat.Tr”)

# check that the matrix was created correctly

ds.ls()

ds.class(“X.mat.Tr”)

ds.dim(“X.mat.Tr”)

# multiply X.mat by its transpose (the product is a 5 by 5 matrix)

ds.matrixMult(M1=“X.mat.Tr”, M2=“X.mat”, newobj=“X.mat.prod”)

# check that the matrix was created correctly

ds.ls()

ds.class(“X.mat.prod”)

ds.dim(“X.mat.prod”)