0

你好堆垛机!这是我的第一个问题,所以我很好奇您是否可以帮助我!:)

首先:我检查了类似的问题,不幸的是没有一个解决方案对我有用。现在尝试了将近 3 天:/ 由于我正在处理敏感数据,因此很遗憾,我无法为 reprex 提供原始表。但是,我将创建一个小的替代示例表进行测试。

要解决问题:

我想使用包“CNorm”来预测规范值。它需要原始数据、分类数据、模型和最小值/最大值以及其他一些不太重要的东西。问题是:无论我做什么,无论我使用什么数据类型和工作目录,它都会给我一个错误“$ 运算符对原子向量无效”,以改变我将原始 .sav 文件转换为数据帧。好吧——什么也没发生。我测试了数据的类型,它说的是数据帧,而不是原子向量。我也尝试使用“[1]”作为位置或使用[“Correct”]作为名称,但仍然出现相同的错误。使用 2 个单个数据框,使用列表也是如此。我尝试使用 $ 来检查,如果我得到不同的错误,但也相同。我什至使用另一个工作区来检查旧工作区是否被窃听。

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

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”来获取列名,但无济于事。

以下是示例数据框。 为了更真实地测试它,我建议使用 2 列和 900 行(+ 列标题)的 Exel 文件(如原始文件)。“正确”值可以由 Excel 随机选择,它们从 35 到 50 不等,年龄从 6 到 12 不等。

正确的 年龄
40 6
45 7
50 6
35 6

我真的希望你们中的某个人能够找出问题以及如何让命令正常运行。我现在真的没有其他想法。

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

4

1 回答 1

1

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

我对您的问题知之甚少,无法说出您需要使用哪种模型来获得所需的答案,但是例如将一个由cnorm()返回构造的对象传递给它,使用您的数据和参数没有错误(有一些警告,因为测试数据集的小尺寸):

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 包于 2020-12-08 创建(v0.3.0)

注意我使用Data_4$ageandData_4$correct作为前两个参数。Data_4[,1]并且Data_4[[1]]也可以工作,但Data_4[1]不能,因为这会返回数据帧的子集,而不是 predictNorm 所期望的向量。

于 2020-12-08T10:28:01.857 回答