Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将命名的数字向量乘以R中的单个数字_R_Function_Dataframe_Vector - Fatal编程技术网

将命名的数字向量乘以R中的单个数字

将命名的数字向量乘以R中的单个数字,r,function,dataframe,vector,R,Function,Dataframe,Vector,在下面的代码中,m3$modelStruct$varStruct返回一个命名的数字向量。但是当我把它乘以σ(m3)^2时,乘法就不会发生了。有解决办法吗 library(nlme) dat <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/var.csv') dat$fmonth <- factor(dat$month) vf2 <- varIdent(form= ~ 1 | fmonth

在下面的代码中,
m3$modelStruct$varStruct
返回一个命名的数字向量。但是当我把它乘以σ(m3)^2时,乘法就不会发生了。有解决办法吗

library(nlme)

dat <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/var.csv')
dat$fmonth <- factor(dat$month)


vf2 <- varIdent(form= ~ 1 | fmonth)

m3 <- lme(y ~ x*fmonth, random = ~1|id, data = dat,
              weights = vf2)


sigma(m3)^2 * m3$modelStruct$varStruct   ## PROBLEM IS HERE!
库(nlme)

dat您将
m3$modelStruct$varStruct
作为命名向量的前提是不正确的。你的乘法运算返回一个

class(sigma(m3)^2 * m3$modelStruct$varStruct)
#[1] "varIdent" "varFunc" 
因此,调用print方法
print.varFunc

如果您确实希望与打印(m3$modelStruct$varStruct)
显示的值相乘,则需要提取系数:

m3$modelStruct$varStruct
#Variance function structure of class varIdent representing
#        5         6         9        10        12         3         4        11         8         2         1         7 
#1.0000000 1.0065306 1.8362431 1.3632609 0.7827463 1.2128426 0.8708676 0.9233713 0.6003184 0.6064313 1.2060820 0.8399081


sigma(m3)^2 * coef(m3$modelStruct$varStruct, uncons = FALSE, allCoef = TRUE)
#       5        6        9       10       12        3        4       11        8        2        1        7 
#4.292699 4.320733 7.882439 5.852068 3.360094 5.206368 3.738372 3.963755 2.576986 2.603227 5.177347 3.605472