尽管未使用原子向量或 $,但出现错误“$ operator is invalid for atomic vectors”

Error "$ operator is invalid for atomic vectors" despite not using atomic vectors or $

各位堆友大家好!这是我的第一个问题,所以我很好奇你能否帮助我! :)

首先:我检查了类似的问题,不幸的是 none 的解决方案对我有用。现在已经尝试了将近 3 天:/ 不幸的是,由于我正在处理敏感数据,因此我无法为 reprex 提供原始 table。但是我会创建一个小的替代 example-table 用于测试。

解决问题:

我想使用包“CNorm”预测一个标准值。它需要原始数据、分类数据、模型和 min/max 值以及其他一些不太重要的东西。问题是:无论我做什么,无论我使用什么 Data-type 和工作目录,它都会给我错误 "$ operator is invalid for atomic vectors" to change that I transformed the原始 .sav-file 到数据框。嗯——什么也没发生。我测试了数据的类型,它说的是数据帧,而不是原子向量。我也尝试使用“[1]”作为位置或使用 [“正确”] 作为名称,但仍然出现相同的错误。使用 2 个单个 Dataframes,使用列表也是如此。我试图用 $ 来检查,如果我得到一个不同的错误,但也是一样的。我什至使用另一个工作区来检查旧工作区是否有问题。

所以也许我只是犯了非常愚蠢的错误,但我真的尝试过但没有成功所以我问你,解决方案可能是什么。 这里有一些数据可以测试! :)

install.packages("haven")
library(haven)
install.packages("CNORM")
library(CNORM)

SpecificNormValue <- predictNorm((Data_4[1]),(Data_4[2]),model = T,minNorm = 12, maxNorm = 75, force = FALSE, covariate = NULL)

所以这是我在数据框“Data_4”上使用的命令之一。我也试过不使用括号或使用“xxx”来获取列名但无济于事。

以下是示例 Dataframe。 为了更真实地测试它,我会推荐一个 Exel-file 具有 2 列和 900 行(+ Column标题)(如原作)。 “正确”值可以由 Excel 随机选择,它们从 35 到 50 不等,年龄从 6 到 12 不等。

Correct Age
40 6
45 7
50 6
35 6

我真的希望你们中有人能找出问题所在以及我如何正确地获得命令运行。我现在真的没有别的想法了。

感谢您检查我的问题,并提前感谢您的宝贵时间!我很高兴收到你的来信!

该错误的来源不是您的数据,而是 predictNorm 的第三个参数:model = T。根据 predictNorm 文档,这应该是“回归模型或 cnorm 对象”。相反,您传递的是一个逻辑值 (T = TRUE),它是一个原子向量,当 predictNorm 尝试使用 $.

访问模型的组件时会导致此错误

我对你的问题了解不够,无法说明你需要使用哪种模型来获得你想要的答案,但是例如传递给它一个由 cnorm() returns 构造的对象使用您的数据和参数没有错误(由于您的测试数据集很小,所以有一些警告):

library(haven)
library(cNORM)
#> Good morning star-shine, cNORM says 'Hello!'

Data_4 <- data.frame(correct = c(40, 45, 50, 35),
                     age = c(6,7,6,6))

SpecificNormValue <- predictNorm(Data_4$correct, 
                                 Data_4$age, 
                                 model = cnorm(Data_4$correct, Data_4$age), 
                                 minNorm = 12, 
                                 maxNorm = 75, 
                                 force = FALSE,
                                 covariate = NULL)
#> Warning in rankByGroup(raw = raw, group = group, scale = scale, weights =
#> weights, : The dataset includes cases, whose percentile depends on less than
#> 30 cases (minimum is 1). Please check the distribution of the cases over the
#> grouping variable. The confidence of the norm scores is low in that part of the
#> scale. Consider redividing the cases over the grouping variable. In cases of
#> disorganized percentile curves after modelling, it might help to reduce the 'k'
#> parameter.
#> Multiple R2 between raw score and explanatory variable: R2 = 0.0667
#> Warning in leaps.setup(x, y, wt = wt, nbest = nbest, nvmax = nvmax, force.in =
#> force.in, : 21 linear dependencies found
#> Reordering variables and trying again:
#> Warning in log(vr): NaNs produced
#> Warning in log(vr): NaNs produced
#> Specified R2 falls below the value of the most primitive model. Falling back to model 1.
#> R-Square Adj. = 0.993999
#> Final regression model: raw ~ L4A3
#> Regression function: raw ~ 30.89167234 + (6.824413606e-09*L4A3)
#> Raw Score RMSE = 0.35358
#> 
#> Use 'printSubset(model)' to get detailed information on the different solutions, 'plotPercentiles(model) to display percentile plot, plotSubset(model)' to inspect model fit.

reprex package (v0.3.0)

于 2020-12-08 创建

请注意,我对前两个参数使用了 Data_4$ageData_4$correctData_4[,1]Data_4[[1]] 也有效,但 Data_4[1] 无效,因为 returns 数据帧的子集不是 predictNorm 预期的向量。