0

我正在使用 systemfit 使用 SUR 方法运行方程组。我需要阅读长(多行)公式。可以使用以下代码访问我的简单可重现数据集。

dat<-structure(list(Time = structure(c(9L, 7L, 15L, 1L, 17L, 13L, 
11L, 3L, 23L, 21L, 19L, 5L, 10L, 8L, 16L, 2L, 18L, 14L, 12L, 
4L, 24L, 22L, 20L, 6L), .Label = c("Apr-00", "Apr-01", "Aug-00", 
"Aug-01", "Dec-00", "Dec-01", "Feb-00", "Feb-01", "Jan-00", "Jan-01", 
"Jul-00", "Jul-01", "Jun-00", "Jun-01", "Mar-00", "Mar-01", "May-00", 
"May-01", "Nov-00", "Nov-01", "Oct-00", "Oct-01", "Sep-00", "Sep-01"
), class = "factor"), ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L), .Label = c("A", "B"), class = "factor"), y1 = c(25L, 
14L, 45L, 15L, 24L, 17L, 18L, 19L, 14L, 15L, 25L, 14L, 45L, 15L, 
24L, 17L, 18L, 19L, 14L, 15L, 25L, 14L, 45L, 15L), y2 = c(4L, 
3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L, 4L, 3L, 4L, 5L, 1L, 
4L, 5L, 3L, 6L, 4L, 2L, 5L), x1 = c(3L, 4L, 1L, 8L, 6L, 7L, 9L, 
7L, 3L, 1L, 2L, 5L, 6L, 3L, 4L, 1L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 
2L), x2 = c(4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L, 4L, 
3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L), x3 = c(3L, 4L, 2L, 
8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L, 5L, 6L, 3L, 4L, 2L, 8L, 6L, 7L, 
9L, 7L, 3L, 1L, 2L), x4 = c(4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 
4L, 2L, 5L, 4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L), 
    x5 = c(3L, 4L, 3L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L, 5L, 6L, 
    3L, 4L, 3L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L)), .Names = c("Time", 
"ID", "y1", "y2", "x1", "x2", "x3", "x4", "x5"), class = "data.frame", row.names = c(NA, 
-24L))

我的示例公式是这样的,

model1<- y1 ~ x1 + x2 + x3
              + x4 +x5 

eqSystem <- list(model1)

library(systemfit)
fit_prod_SUR <- systemfit(eqSystem, method= "SUR", data=dat)
print(fit_prod_SUR)

我必须在 eqSystem 中包含几个非常长的公式。但我的问题是因为我的公式(例如model1)很长,它有多行。当我使用 systemfit 运行 eqSystem 时,它只读取每个公式第一行中的变量。我尝试使用以下代码,但它不起作用。

model1<- (get(paste("y1 ~ x1 + x2 + x3",
                         " + x4 + x5", sep="")))

但它不作为一个公式。请任何人都可以帮助我如何读取 R 中公式的所有变量(多行)。

4

0 回答 0