【发布时间】:2021-08-16 03:51:59
【问题描述】:
我正在尝试使用 nlme 包将第二类分布的广义 beta 拟合到模拟的健康成本数据。
在测试数据集上运行以下代码:
包安装(如有必要)
install.packages("withr", dependencies = T)
library(withr)
with_makevars(c(PKG_CFLAGS ="-std=gnu99"),
install.packages("cubature"), assignment="+=")
install.packages("GB2", dependencies = T)
install.packages("nlme", dependencies = T)
# load packages
library(cubature)
library(GB2)
library(nlme)
# Binary independent variables
age <- rbinom(n=1000, size=1, prob=.3)
sex <- rbinom(n=1000, size=1, prob=.5)
trmt <- rbinom(n=1000, size=1, prob=.5)
# GB2 parameter equations
shape1 <- exp(rnorm(n=1000, mean=.1 + age/100 - sex/10 + trmt/10, sd=.3))
scale <- exp(rnorm(n=1000, mean=7 + age/50 + sex - trmt, sd=.5))
shape2 <- exp(rnorm(n=1000, mean=1.5 + age/100 + sex/10 - trmt/10, sd=.3))
shape3 <- exp(rnorm(n=1000, mean=.5 + age/100 - sex/10 - trmt/10, sd=.3))
# Outcome
y <- rgb2(1000, shape1, scale, shape2, shape3)
# Create test dataset
df <- data.frame(cbind(y,age,sex,trmt,shape1,scale,shape2,shape3))
# Fit GB2 distribution to data
gb2_fit <- nlme(y ~ scale*beta(shape2 + 1/shape1, shape3 - 1/shape1)/beta(shape2, shape3),
# data = list(y=df_gb2_test[,1]),
data = df,
fixed = list(shape1 ~ age + sex + trmt,
scale ~ age + sex + trmt,
shape2 ~ age + sex + trmt,
shape3 ~ age + sex + trmt),
start = list(fixed = c(shape1 = 1.00, scale = 100, shape2 = 1.00, shape3 = 1.00)))
我得到错误:
Error in parse(text = paste("~", paste(nVal, collapse = "/"))) :
<text>:2:0: unexpected end of input
1: ~
^
任何想法我做错了什么?我似乎正确地使用了波浪号运算符。
【问题讨论】: