# PAsso: an R Package for Assessing Partial Association between Ordinal Variables

## Overview

An R package of a unified framework for assessing Parrtial Association between Ordinal variables. It includes quantification, visualization, and hypothesis testing. All the products are based on the paper by Dungang Liu, Shaobo Li, Yan Yu and Irini Moustaki (2020) and the approach described in Dungang and Zhang (2017).

## Installation

The `PAsso` package is currently not available on PAsso CRAN and wait for future updates.

### Install the development version from GitHub

``````if (!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("XiaoruiZhu/PAsso")``````

## Example

This is a basic example which shows you how to solve a common problem:

``````library(PAsso)

PAsso_1 <- PAsso(responses = c("PreVote.num", "PID"),
data = ANES2016,
uni.model = "probit",
method = c("kendall")
)

# Print the partial association matrix only
print(PAsso_1, 5)

# Provide partial association matrix, marginal association matrix, and summary of models' coefficients
summary(PAsso_1, 4)

# Plot partial association regression plot: residuals
plot(PAsso_1)

# Retrieve residuals
test_resids <- residuals(PAsso_1, draw = 1)
dim(test_resids)

# Association analysis between three ordinal responses ----------

PAsso_2 <- PAsso(responses = c("PreVote.num", "PID", "selfLR"),
data = ANES2016,
uni.model <- "probit",
method = c("kendall"),
resids.type = "surrogate")

# Compare marginal correlation and partial correlation.
summary(PAsso_2, digits=4)
plot(PAsso_2)

# test function: Conduct inference based on object of "PAsso.test" class ----------------------------
library(progress); #library(doParallel)

system.time(Pcor_SR_test1 <- test(object = PAsso_2, boot_SE=100, H0=0, parallel=F))
print(Pcor_SR_test1, digits=6)
print(PAsso_2, 6)

# diagnostic.plot function -----------------------------------------------------
check_qq <- diagnostic.plot(object = PAsso_2, output = "qq")

check_fitted <- diagnostic.plot(object = PAsso_2, output = "fitted")

check_covar <- diagnostic.plot(object = PAsso_2, output = "covariate")

# general association measure and 3-D plot for VOTE and PID ------------------
library("copula")
library("plotly")

# Draw all pairs
testPlots <- plot3D(PAsso_1)
testPlots\$`PreVote.num v.s. PID`

# Draw just one pair
testPlots2 <- plot3D(object = PAsso_2, y1 = "selfLR", y2 = "PID")
testPlots2

# "PAsso" advanced using of the function: Input a few models directly ------------------------------

fit_vote <- glm(PreVote.num ~ income.num + age + edu.year, data = nes2016,
summary(fit_vote)

fit_PID <- polr(as.factor(PID) ~ income.num + age + edu.year, data = nes2016,
method = "probit", Hess = TRUE)

summary(fit_PID)

association = c("partial"),
method = c("kendall"),
resids.type = "surrogate")
)

# Partial association coefficients (Parts of Table 7 in paper)