I am running this R script from Java (I am using Renjin):
getCoefficients <- function(x, y, Regions) {
print(class(x)) #"matrix"
print(dim(x)) #8 456
print(class(y)) #"numeric"
print(length(y)) #456
print(Regions) #"r1" "r2" "r3"
nbRegions <- length(Regions)
lengthY <- length(y)
colRegions <- NULL
from <- 1
to <- lengthY / nbRegions
for (i in 1:nbRegions) {
region <- Regions[i]
c <- cbind(region, from:to)
colRegions <- rbind(colRegions, c)
}
indexCols <- as.data.frame(colRegions)
print(class(indexCols)) #"data.frame"
print(dim(indexCols)) #456 2
x_ <- t(x)
print(class(x_)) #"matrix"
print(dim(x_)) #456 8
data_ <- cbind(indexCols, y, x_)
print(class(data_)) #"data.frame"
print(dim(data_)) #456 11
dataFrame <- pdata.frame(data_)
print(class(dataFrame)) #"pdata.frame" "data.frame"
print(dim(dataFrame)) #456 11
colnames(dataFrame) <- c("region", "date", "y", "a", "b", "c", "d", "e", "f", "r", "o")
model_RE_S <- try(plm(y ~ x_, data = dataFrame, model = "random", index = c("region", "date"), effect = "twoways")) #Error : replacement has 3648 rows, data has 456 :rotating_light:
summryModel <- summary(model_RE_S)
coeff <- as.numeric(summryModel$coefficients)
#print(summryModel)
return(coeff)
}
I am getting the following error and I have no idea how to resolve it:
Error : replacement has 3648 rows, data has 456
The dimensions of the data I am using are:
- 3 regions (r1, r2, r3)
- 8 variables
- 456 observations (3 regions x 152 weeks)
- y is the dependent variable (456 data points for all 3 regions)
- x is the matrix with the data of the 8 dependent variables so its dimensions are (456 columns and 8 rows), and x_ (its transpose) is what will be used in the modelling.
a sample of x looks like:
a sample of x_ the transpose of x :
a sample of data_ :
a sample of dataFrame :
thank you!