'lme: length of 'dimnames' [2] not equal to array extent
I was able to successfully run the codes at the bottom without errors. However, I received the error
Error in matrix(unlist(value), nrow = nrow(data), dimnames = list(row.names(data), :
length of 'dimnames' [2] not equal to array extent
after
- only selected the variables used in the analysis from a bigger dataset
myVars<-c("Country", "familism_mean", "avoidance", "anxiety", "n1", "n2", "d1", "d2", "t", "m1","m2","GDP","HDI","self_expression","long_term_orientation", "power_distance","Residential_mobility", "age", "ses","gender")
data01<-data01[myVars]
- or manually deleted the variables that are not used in the bigger dataset
Original codes
rm(list=ls())
data01 <- read.csv(file="c://Users//Xian//Dropbox//CCFSN_PSPB submission//Submission folder//Data.csv",header=TRUE)
names(data01)
data01$Z_avoidance = (data01$avoidance-mean(data01$avoidance, na.rm=T))/sd(data01$avoidance, na.rm=TRUE)
data01$Z_anxiety = (data01$anxiety-mean(data01$anxiety, na.rm=T))/sd(data01$anxiety, na.rm=TRUE)
data01$Z_familism= (data01$familism_mean-mean(data01$familism_mean, na.rm=T))/sd(data01$collectivism_mean, na.rm=TRUE)
data01$Z_long_term = (data01$long_term_orientation-mean(data01$long_term_orientation, na.rm=T))/sd(data01$long_term_orientation, na.rm=TRUE)
data01$Z_power_distance = (data01$power_distance-mean(data01$power_distance, na.rm=T))/sd(data01$power_distance, na.rm=TRUE)
data01$Z_self_expression = (data01$self_expression-mean(data01$self_expression, na.rm=T))/sd(data01$self_expression, na.rm=TRUE)
data01$Z_Residential_mobility = (data01$Residential_mobility-mean(data01$Residential_mobility, na.rm=T))/sd(data01$Residential_mobility, na.rm=TRUE)
data01$Z_GDP = (data01$GDP-mean(data01$GDP, na.rm=T))/sd(data01$GDP, na.rm=TRUE)
data01$Z_HDI = (data01$HDI-mean(data01$HDI, na.rm=T))/sd(data01$HDI, na.rm=TRUE)
data01$Z_age = (data01$age-mean(data01$age, na.rm=T))/sd(data01$age, na.rm=TRUE)
data01$Z_ses = (data01$ses-mean(data01$ses, na.rm=T))/sd(data01$ses, na.rm=TRUE)
library(RSA)
library(reshape)
library(nlme)
library(lme4)
library(lmerTest)
#==================familism * avoidance = n1==================
rsa.data <- rename(data01, c(Z_familism = "predictor1", #Replace "yourpredictor1" with the variable name of your first predictor
Z_avoidance = "predictor2", #Replace "yourpredictor2" with the variable name of your second predictor
n1 = "outcome")) #Replace "youroutcome" with the variable name of your outcome
rsa.data <- within.data.frame(rsa.data, {
centered.predictor1 <- predictor1 - 0 #Center predictor 1
centered.predictor2 <- predictor2 - 0 #Center predictor 2
squared.predictor1 <- centered.predictor1* centered.predictor1 #Create squared term
squared.predictor2 <- centered.predictor2* centered.predictor2 #Create squared term
interaction <- centered.predictor1* centered.predictor2 #Create interaction term
})
mlm.model <- lme(outcome ~ centered.predictor1+centered.predictor2 + squared.predictor1 + interaction +squared.predictor2+Z_anxiety
+gender+Z_long_term+Z_power_distance+Z_self_expression+Z_Residential_mobility+Z_GDP+Z_HDI+Z_age+Z_ses,
data = rsa.data,
random = ~ 1|Country, # Replace "nesting.variable" with the name of your nesting variable
na.action = "na.omit")
summary(mlm.model) #View Model
vcov(mlm.model) #View covariance of model
So I was confused. Why selecting variables can create this error? Any thoughts? Thank you in advance for your help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
