我试图找到一种从几个二项分布生成相关随机数的方法.
我知道如何使用正态分布(使用mvrnorm),但我找不到适用于二项式的函数.
当您想将S4对象保存到列表列表中并且该元素先前尚未定义时,R给出以下消息错误。
"invalid type/length (S4/0) in vector allocation"
为什么使用简单列表而不使用列表列表?
请参见以下代码和潜在的解决方法。但是,我很确定还有一个更明显的解决方案。
# Creation of an S4 object
setClass("student", slots=list(name="character", age="numeric", GPA="numeric"))
s <- new("student",name="John", age=21, GPA=3.5)
# Indexes for the list
index1 <- "A"
index2 <- "a"
# Simple list (All of this works)
l <- list()
l[[index1]] <- s
l[[index1]] <- "character"
l[[index1]] <- 999
# List of list
l <- list()
l[[index1]][[index2]] <- s # will give an Error!!
l[[index1]][[index2]] <- "character" # still working
l[[index1]][[index2]] <- 999 # still …Run Code Online (Sandbox Code Playgroud) 使用方法“fREML”和“REML”拟合相同的模型bam给了我接近的结果,但解释的偏差与返回的相当不同summary.gam。
使用“fREML”时,数量约为 3.5%(不好),而使用“REML”时,数量约为 50%(还不错)。怎么可能?哪一个是正确的?
不幸的是,我无法提供一个简单的可重现的示例。
#######################################
## method = "fREML", discrete = TRUE ##
#######################################
Family: binomial
Link function: logit
Formula:
ObsOrRand ~ s(Var1, k = 3) + s(RandomVar, bs = "re")
Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -5.0026 0.2199 -22.75 <2e-16
Approximate significance of smooth terms:
edf Ref.df Chi.sq p-value
s(Var1) 1.00 1.001 17.54 2.82e-05
s(RandomVar) 16.39 19.000 145.03 < 2e-16
R-sq.(adj) = 0.00349 Deviance explained = 3.57%
fREML = 2.8927e+05 Scale …Run Code Online (Sandbox Code Playgroud)