繁体   English   中英

当将数据名称作为另一个函数中的参数应用到gls函数时,数据名称将不会保留

[英]Data name won't carry through when applied to gls function as an argument inside another function

使用包nlme ,我有模型:

gls(temp.avg ~ year, data = df, method = 'ML')

这确实符合我的期望。 但是,当我函数中使用gls函数的数据参数更改模型来创建模型时,我的模型不再使用数据“ df”,而是仅打印“ dat”。 这是函数:

function(dat) { gls(temp.avg ~ year, data = dat, method = 'ML') }

这是我在包装器函数外部创建模型时(第一次)然后在函数内部创建模型(第二次)时查看模型时的样子[请注意“数据”行]:

Generalized least squares fit by maximum likelihood
  Model: temp.avg ~ year 
  Data: df 
  Log-likelihood: -3877.052

Coefficients:
   (Intercept)         (year) 
  15.135135363   -0.008796849 

Degrees of freedom: 1116 total; 1114 residual
Residual standard error: 7.807791

##########################

Generalized least squares fit by maximum likelihood
  Model: temp.avg ~ year
  Data: dat 
  Log-likelihood: -3877.052

Coefficients:
   (Intercept)         (year)  
  15.135135363   -0.008796849 

Degrees of freedom: 1116 total; 1114 residual
Residual standard error: 7.807791 

我真的很想不要这样做。

我怎样才能获得继承自dat vs“ dat”本身的功能?

library(nlme)
fun <- function(dat) { 
  res <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), dat) 
  res$call$data <- substitute(dat)
  res
}
fun(Ovary)
#Generalized least squares fit by REML
#  Model: follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time) 
#  Data: Ovary 
#  Log-restricted-likelihood: -898.434
#
#Coefficients:
#       (Intercept) sin(2 * pi * Time) cos(2 * pi * Time) 
#        12.2155822         -3.3396116         -0.8697358 
#
#Degrees of freedom: 308 total; 305 residual
#Residual standard error: 4.486121 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM