R 为什么我会收到一条错误消息:“quot;“不一致的参数”;,即使我的矩阵中没有NA值?

R 为什么我会收到一条错误消息:“quot;“不一致的参数”;,即使我的矩阵中没有NA值?,r,R,我正在尝试运行《态度网络分析:简短教程》中的r代码 你可以找到它 首先,我们加载认知态度 unzip('ANES2012.zip') ANES2012 <- read.dta('anes_timeseries_2012_Stata12.dta')#loads the data to the object ANES2012 ######################### #Recode variables #Items regarding Obama ObamaCog <-

我正在尝试运行《态度网络分析:简短教程》中的r代码

你可以找到它

首先,我们加载认知态度

unzip('ANES2012.zip')
ANES2012 <- read.dta('anes_timeseries_2012_Stata12.dta')#loads the data to the object ANES2012

#########################
#Recode variables 
#Items regarding Obama

ObamaCog <- data.frame(Mor = as.numeric(ANES2012$ctrait_dpcmoral),#this creates a data frame containing the items tapping beliefs
                        Led = as.numeric(ANES2012 $ ctrait_dpclead),
                        Car = as.numeric(ANES2012$ctrait_dpccare),
                        Kno = as.numeric(ANES2012$ctrait_dpcknow),
                        Int = as.numeric(ANES2012$ctrait_dpcint),
                        Hns = as.numeric(ANES2012$ctrait_dpchonst))
ObamaCog[ObamaCog < 3] <- NA#values below 3 represent missing values
然后我们对情感态度也做了同样的实验:

ObamaAff <- data.frame(Ang = as.numeric(ANES2012$candaff_angdpc),#this creates a data frame containing the items tapping feelings
                        Hop = as.numeric(ANES2012$candaff_hpdpc), 
                        Afr = as.numeric(ANES2012$candaff_afrdpc), 
                        Prd = as.numeric(ANES2012$candaff_prddpc))
ObamaAff[ObamaAff < 3] <- NA#values below 3 represent missing values
ObamaAff <- binarize(ObamaAff, 4)#(not) endorsing the feelings is encoded as 1 (0)
然后我们忽略了NA值:

Obama <- na.omit(Obama)
我的矩阵中不再有NA值

我认为它符合要求的结构:nobs x nvars

    Mor Led Car Kno Int Hns Ang Hop Afr Prd
2     0   0   0   0   0   0   0   0   0   0
3     0   0   0   0   0   0   0   0   0   0
4     0   0   0   0   0   0   0   0   0   0

直到5914年。如果之前的行中有NA值,那么现在就丢失了。(例如第64行)

如果我正在尝试运行
IsingFit
-功能:

ObamaFit <- IsingFit(Obama)

我是R的初学者,我假设不一致的参数是
NA
-值,但事实似乎并非如此。有谁能告诉我错误消息的含义以及如何解决问题,以便我可以使用
IsingFit
-函数吗?

很明显,
IsingFit
需要一个矩阵作为输入。而是传递一个data.frame。如果你做了
ObamaFit@Roland,它还能工作吗?它仍然会给我同样的错误信息。通过
ObamaFit,您的矩阵是否具有所需的结构,即“矩阵的维数为nobs x nvars;每行都是变量的观察向量。必须是横截面数据。”?@Roland i在帖子中提供了一些关于数据结构的信息。我认为这不是问题所在。或者你仍然这么认为?很明显,
IsingFit
需要一个矩阵作为输入。而是传递一个data.frame。如果你做了
ObamaFit@Roland,它还能工作吗?它仍然会给我同样的错误信息。通过
ObamaFit,您的矩阵是否具有所需的结构,即“矩阵的维数为nobs x nvars;每行都是变量的观察向量。必须是横截面数据。”?@Roland i在帖子中提供了一些关于数据结构的信息。我认为这不是问题所在。还是你仍然这么认为?
write.csv(Obama, file = "Obama-Excel1")
    Mor Led Car Kno Int Hns Ang Hop Afr Prd
2     0   0   0   0   0   0   0   0   0   0
3     0   0   0   0   0   0   0   0   0   0
4     0   0   0   0   0   0   0   0   0   0
60    0   0   0   0   0   0   0   0   0   0
61    1   1   1   1   1   1   0   0   0   0
62    0   0   0   0   0   0   0   0   0   0
63    0   0   0   0   0   0   0   0   0   0
65    0   1   1   0   0   1   0   0   0   0
66    1   1   1   1   1   1   0   0   0   0
67    0   0   0   0   0   0   0   0   0   0
ObamaFit <- IsingFit(Obama)
Error in y %*% rep(1, nc) : non-conformable arguments