政治學w-nominate語法問題請教

21 views
Skip to first unread message

Chen Chen

unread,
Sep 29, 2022, 11:40:06 PM9/29/22
to R軟體使用者論壇
各位先進好:

  後學在使用政治學界的w-nominate時遇到了問題,無論結果怎麼跑,最後產出的coord1d都是呈現1與-1,沒有更大的variation,想請問各位先進,是否是後學的語法有錯誤?最後也附上語法及使用檔。


porkwnominate <- as.matrix(porkwnominate)
porkwnominate[1:113, 1:182]

names <- porkwnominate[, 1]

legData <- matrix(porkwnominate[, 2], length(porkwnominate[, 2]), 1)
colnames(legData) <- "party"
porkwnominate <- porkwnominate[, -c(1, 2)]

pork <- rollcall(porkwnominate, yea = c(1), nay = c(4), missing =0,
               notInLegis =9  , legis.names = names,
               legis.data = legData)
result <- wnominate(pork, dim=2, polarity =c(39,44))
summary(pork)
summary(rc)
summary(result)
plot(result)

library(wnominate)
library(pscl)


porkwnominate <- as.matrix(porkwnominate)
porkwnominate[1:113, 1:182]

names <- porkwnominate[, 1]

legData <- matrix(porkwnominate[, 2], length(porkwnominate[, 2]), 1)
colnames(legData) <- "party"
porkwnominate <- porkwnominate[, -c(1, 2)]

pork <- rollcall(porkwnominate, yea = c(1), nay = c(4), missing =0,
               notInLegis =9  , legis.names = names,
               legis.data = legData)
result <- wnominate(pork, dim=2, polarity =c(39,44))
summary(pork)
summary(rc)
summary(result)
plot(result)
porkwnominate.xlsx

WEPA ^_^

unread,
Nov 18, 2022, 10:08:28 AM11/18/22
to R軟體使用者論壇
Hi friend, 參考以下建議:

1. 考量匯入檔案為 Excel, 因此使用 readxl 套件
library(readxl)
porkwnominate <- read_excel("porkwnominate.xlsx", col_names=FALSE) # 113*182


2. 在程式碼 pork <- rollcall(porkwnominate, ...) 之前須進行資料轉換.
# 將字串矩陣(character matrix)轉換為數值矩陣(numeric matrix)
porkwnominate <- matrix(as.numeric(porkwnominate), ncol = ncol(porkwnominate))


3. 繪圖結果確實為-1與1, 其原因可能是原始Excel資料中, DPP的資料大部分為1, KMT大部分為4, 因此使用wnominate函數進行估計時,不會有內建範例之估計與繪圖結果.
# end

pig841...@gmail.com 在 2022年9月30日 星期五上午11:40:06 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages