Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE #21

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions .github/workflows/mac_r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install JAGS on macOS
run: brew install jags

- name: Install LaTeX on macOS
run: brew install --cask mactex-no-gui

- name: Set up R ${{ matrix.r-version }}
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r-version }}

- name: Install system dependencies on MacOS
run: |
brew install pkg-config
brew install qpdf
brew install ghostscript
brew install --cask mactex-no-gui # Install LaTeX

- name: Set CRAN mirror and install R package dependencies
env:
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
GITHUB_PAT: ${{ secrets.MY_GITHUB_PAT }} # 使用新的 Secret 名称 MY_GITHUB_PAT
run: |
Rscript -e "options(repos = c(CRAN = 'https://cloud.r-project.org/')); install.packages(c('remotes', 'knitr'));"
Rscript -e "options(repos = c(CRAN = 'https://cloud.r-project.org/')); install.packages(c('remotes', 'rjags', 'ggplot2', 'knitr'));"
Rscript -e "remotes::install_github('cran/basicspace')"

- name: Install rcmdcheck package
run: |
Expand All @@ -56,10 +56,3 @@ jobs:
- name: Test (optional)
run: |
Rscript -e "devtools::test()"

env:
_R_INSTALL_TIME_PATCHES_: no
R_LIBS_USER: ${{ runner.temp }}/Library
TZ: UTC
_R_CHECK_SYSTEM_CLOCK_: FALSE
NOT_CRAN: true
23 changes: 12 additions & 11 deletions .github/workflows/r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:

jobs:
build:
runs-on: ${{ matrix.os }}
runs-on: windows-latest
strategy:
matrix:
os: [windows-latest]
Expand All @@ -33,7 +33,6 @@ jobs:
r-version: ${{ matrix.r-version }}

- name: Install system dependencies on Windows
if: runner.os == 'Windows'
run: |
choco install qpdf
choco install pkgconfiglite
Expand All @@ -42,9 +41,10 @@ jobs:

- name: Set CRAN mirror and install R package dependencies
env:
GITHUB_PAT: ${{ secrets.GITHUB_PAT }}
GITHUB_PAT: ${{ secrets.MY_GITHUB_PAT }} # 使用新的 Secret 名称 MY_GITHUB_PAT
run: |
Rscript -e "options(repos = c(CRAN = 'https://cloud.r-project.org/')); install.packages(c('remotes', 'knitr'));"
Rscript -e "options(repos = c(CRAN = 'https://cloud.r-project.org/')); install.packages(c('remotes', 'rjags', 'ggplot2', 'knitr'));"
Rscript -e "remotes::install_github('cran/basicspace')"

- name: Install rcmdcheck package
run: |
Expand All @@ -57,10 +57,11 @@ jobs:
- name: Test (optional)
run: |
Rscript -e "devtools::test()"
shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
env:
_R_INSTALL_TIME_PATCHES_: no
R_LIBS_USER: D:\a\_temp\Library
TZ: UTC
_R_CHECK_SYSTEM_CLOCK_: FALSE
NOT_CRAN: true

shell: pwsh
env:
_R_INSTALL_TIME_PATCHES_: no
R_LIBS_USER: ${{ runner.temp }}/Library
TZ: UTC
_R_CHECK_SYSTEM_CLOCK_: FALSE
NOT_CRAN: true
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ export(diffStims)
export(doubleCenter)
export(doubleCenterRect)
export(gray.palette)
export(makeCutlineAngles)
export(mlsmu6)
export(plot_blackbox)
export(plot_oc_rollcall)
export(plot_resphist)
export(plot_rollcall)
export(plot_wnom_coords)
export(rc.errors)
import(ellipse)
import(ggplot2)
importFrom(MASS,polr)
importFrom(basicspace,aldmck)
Expand Down
77 changes: 77 additions & 0 deletions R/makeCutlineAngles.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#' Calculate Cutline Angles
#'
#' The `makeCutlineAngles` function calculates the cutline angles for a given object of class `wnominate`, which can either be a `nomObject` or `OCobject`. The function processes the roll call data and computes the angles associated with the cutlines.
#'
#' @param obj An object of class `wnominate`, which can either be a `nomObject` or `OCobject`. This object contains roll call data and other relevant information needed to calculate the cutline angles.
#'
#' @return A data frame with three columns:
#' \describe{
#' \item{angle}{The calculated cutline angles in degrees.}
#' \item{N1W}{The adjusted first component of the normal vector to the cutline.}
#' \item{N2W}{The adjusted second component of the normal vector to the cutline.}
#' }
#'
#' @details
#' The function differentiates between objects of class `nomObject` and `OCobject` to perform appropriate calculations. It uses the roll call data within the object to compute the normal vectors and their corresponding angles.
#'
#' @examples
#' \dontrun{
#' # Assuming `wnominate_obj` is a valid wnominate object of class `nomObject` or `OCobject`
#' result <- makeCutlineAngles(wnominate_obj)
#' print(result)
#' }
#'
#' @keywords datasets
#' @export
makeCutlineAngles <- function(obj){
if("nomObject" %in% class(obj)){
WEIGHT <- (obj$weights[2])/(obj$weights[1])
DL1 <- obj$rollcalls[,7]
DL2 <- obj$rollcalls[,8]
ZM1 <- obj$rollcalls[,9]
ZM2 <- obj$rollcalls[,10]
YEA1 <- ZM1 - DL1
YEA2W <- (ZM2 - DL2) * WEIGHT
NAY1 <- ZM1 + DL1
NAY2W <- (ZM2 + DL2) * WEIGHT
A1 <- NAY1 - YEA1
A2 <- NAY2W - YEA2W
ALENGTH <- sqrt(A1*A1 + A2*A2)
N1W <- A1 / ALENGTH
N2W <- A2 / ALENGTH
for (i in 1:nrow(obj$rollcalls)){
if (N1W[i] < 0 & !is.na(N2W[i])) N2W[i] <- -N2W[i]
if (N1W[i] < 0 & !is.na(N1W[i])) N1W[i] <- -N1W[i]
}
C1 <- N2W
C2 <- -N1W
for (i in 1:nrow(obj$rollcalls)){
if (C1[i] < 0 & !is.na(C2[i])) C2[i] <- -C2[i]
if (C1[i] < 0 & !is.na(C1[i])) C1[i] <- -C1[i]
}
theta <- atan2(C2,C1)
theta4 <- theta * (180/pi)
}
if("OCobject" %in% class(obj)){
oc1 <- obj$legislators[,7]
oc2 <- obj$legislators[,8]
PRE <- obj$rollcalls[,5]
N1 <- obj$rollcalls[,6]
N2 <- obj$rollcalls[,7]
ws <- obj$rollcalls[,8]
xws <- ws * N1
yws <- ws * N2
C1 <- N2
C2 <- -N1
for (i in 1:nrow(obj$rollcalls)){
if (C1[i] < 0 & !is.na(C2[i])) C2[i] <- -C2[i]
if (C1[i] < 0 & !is.na(C1[i])) C1[i] <- -C1[i]
}
theta <- atan2(C2,C1)
theta4 <- theta * (180/pi)
N1W <- N1
N2W <- N2
}
res <- data.frame(angle = theta4, N1W = N1W, N2W = N2W)
return(res)
}
38 changes: 19 additions & 19 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ template:
development:
mode: auto

reference:
- title: Helper Functions
desc: <div class="text-justify"></div>
- contents:
- BAM
- BMDS
- aldmckSE
- bamPrep
- boot.aldmck
- boot.blackbox
- boot.blackbox_transpose
- diffStims
- doubleCenter
- doubleCenterRect
- gray.palette
- mlsmu6
- plot_blackbox
- plot_resphist
- plot_oc_rollcall
# reference:
# - title: Helper Functions
# desc: <div class="text-justify"></div>
# - contents:
# - BAM
# - BMDS
# - aldmckSE
# - bamPrep
# - boot.aldmck
# - boot.blackbox
# - boot.blackbox_transpose
# - diffStims
# - doubleCenter
# - doubleCenterRect
# - gray.palette
# - mlsmu6
# - plot_blackbox
# - plot_resphist
# - plot_oc_rollcall


navbar:
Expand Down
1 change: 1 addition & 0 deletions man/ANES1968.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ANES2004.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/anes.input.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/bamdata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions man/binary.comparisons.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/book_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/issues.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/issues.sweden.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/makeCutlineAngles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions man/plot_oc_rollcall.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading