rdataframelme4multilevel-analysis

Uploading a .dat file into R to use the lme() function, having trouble


I uploaded a .dat file in R to perform some multilevel modeling on it. It allows me to check the dimension

dim(lang.IQ.data.set)
[1] 3758   11

I ran the library(nlme) to run the package to use the lme()

I then tried to run my null model

null=lme(fixed = langPOST~1 , random = 1|schoolnr, data=lang.IQ.data.set)

I keep getting this error message for my code

Error in reStruct(random, REML = REML, data = NULL) : 
  object 'schoolnr' not found

I then ran data(lang.IQ.data.set)

and got the error message

Warning message:
In data(lang.IQ.data.set) : data set ‘lang.IQ.data.set’ not found

It appears my .dat file has not been put in? even though it shows up as being imported in R studio? Since it also cannot find the column in the data set "schoolnr"

Hope this makes since, thanks. I am stuck


Solution

  • data() is a command for loading data from packages---and is rarely needed at all. You have already loaded data from a file, and by dim(lang.IQ.data.set) giving the dimensions of it, evidently it worked--at least somewhat. The issue seems to be that is doesn't have a column named schoolnr. (Your error says "schoolnr not found", "lang.IQ.data.set not found".) Look at names(lang.IQ.data.set) to see the column names of your loaded data.

    Additionally, you have a syntax error. Random effects need to start with a ~ so R knows it's a formula. Use random = ~ 1|schoolnr in your call.