简体   繁体   中英

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

Hello fellow Stackers! This is my first question so i am curious if you can help me: :)

First: I checked similar questions and unfortunately none of the solutions worked for me. Tried it for nearly 3 days now:/ Since I am working with sensitive data I cannot provide the original table for reprex, unfortunately. However I will create a small substitutional example-table for testing.

To get to the problem:

I want to predict a norm value using the package "CNorm". It requires raw data, classification data, a model and min/max values and some other things that are less important. The problem is: Whatever I do, whatever Data-type and working directory I use, it gives me the error "$ operator is invalid for atomic vectors" to change that I transformed the original.sav-file to a Dataframe. Well- nothing happened. I tested the type of the data and it said dataframe, not atomic vector. Also i tried using "[1]" for location or ["Correct"] for names but still the same error showed up. Same for using 2 single Dataframes, using lists. I have tried to use $ to check, if i get a different error but also the same. I even used another workspace to check if the old workspace was bugged.

So maybe I just did really stupid mistakes but I really tried and it did not work out so I am asking you, what the solution might be. Here is some data to test: :)

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)

So that is one of the commands I used on the Dataframe "Data_4". I also tried not using brackets or using "xxx" to get the column names but to no avail.

The following is the example Dataframe. To test it more realistic I would recommend an Exel-file with 2 columns and 900 rows(+ Column title) (like the original). The "correct"-values can be random selected by Excel and they differ from 35 to 50, the age differs from 6 to 12.

Correct Age
40 6
45 7
50 6
35 6

I really hope someone of you can figure out the problem and how I get the command properly running. I really have no other idea right now.

Thanks for checking my question and thanks in advance for your time! I would be glad to hear from you!

The source of that error isn't your data, it's the third argument to predictNorm: model = T . According to the predictNorm documentation, this is supposed to be a "regression model or a cnorm object". Instead you are passing in a logical value ( T = TRUE ) which is an atomic vector and causes this error when predictNorm tries to access the components of the model with $ .

I don't know enough about your problem to say what kind of model you need to use to get the answer you want, but for example passing it an object constructed by cnorm() returns without an error using your data and parameters (there are some warnings because of the small size of your test dataset):

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.

Created on 2020-12-08 by the reprex package (v0.3.0)

Note I used Data_4$age and Data_4$correct for the first two arguments. Data_4[,1] and Data_4[[1]] also work, but Data_4[1] doesn't, because that returns a subset of a data frame not a vector as expected by predictNorm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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