---
title: "Frequently Asked Questions"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{FAQ}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

options(rmarkdown.html_vignette.check_title = FALSE)

```

Below are some frequently asked questions about the **procs** package. Click
on the links below to navigate to the full question and answer content.

## Index{#top}

* [Why did you write the procs package?](#why)
* [Are these functions validated?](#validation)
* [Why is the output different?](#different)
* [Can you do N-way tables?](#nway)
* [Can these procedures create plots?](#plots)
* [Does the package support Cochran-Mantel-Haenszel Statistics?](#cmh)
* [What about PROC COMPARE?](#compare)
* [Are there any other statistics procedures coming?](#other)
* [How do I get my statistics into a report?](#outputs)
* [How do I order my frequencies?](#order)


## Content

### Why did you write the **procs** package? {#why}

**Q:** There are already many statistical functions and packages in R.  Why did
you write **procs**?

**A:** I wrote the **procs** package to help SAS® programmers. There are 
many SAS® programmers trying to learn R and struggling with the many 
differences between these two languages.  The **procs** package provides them with
a set of functions that are conceptually similar to SAS® procedures. The aim
is to make them more productive and comfortable working in R in a shorter
time frame.

[top](#top) 

******

### Are these functions validated? {#validation}

**Q:** My company requires that all software be validated before using in 
production. Is the **procs** package validated?

**A:** Yes.  The functions were validated by comparing to SAS®. The validation
documentation is [here](https://r-sassy.org/validation/Procs_Validation.pdf).

[top](#top) 

******

### Why is the output different? {#different}

**Q:** The output dataset columns and column names are a little bit
different from SAS®.  Why?

**A:** The output datasets and column names have been standardized.  They should be
more predictable and easier to manipulate programmatically. They were
changed intentionally as an improvement over the corresponding SAS® procedures.

[top](#top) 

******

### Can you do N-way tables? {#nway}

**Q:** I see you can do one-way and two-way frequency tables. What about
N-way tables?  Does the package support them?

**A:** No.  N-way tables are less common, and were not seen as a priority.
These types of tables are on the list for a future enhancement. The package
does support 2-way frequency tables with one or more by variables.

[top](#top) 

******

### Can these procedures create plots? {#plots}

**Q:** I'm trying to find the option to produce a plot, and can't find it.
Does the package support plots or not?


**A:** Yes. As of **procs** version 1.0.8, the `proc_freq()`, `proc_ttest()`,
and `proc_reg()` functions produce plots.  To get a default set of plots,
set `plots = TRUE` for the desired function.  The documentation for each
function has more information on the types of charts that can be produced,
and various options.

[top](#top) 

******

### Does the package support Cochran-Mantel-Haenszel Statistics? {#cmh}

**Q:** I see the frequency function supports Chi-square and Fishers's exact
tests.  What about Cochran-Mantel-Haenszel?

**A:** CMH statistics were left out of the of the **procs** package because the
corresponding R function does not match SAS® reliably.  You can run CMH statistics
yourself using using the 
[mantelhaen.test](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/mantelhaen.test.html)
function
from the [stats](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/00Index.html)
package.  

[top](#top)

****** 

### What about PROC COMPARE? {#compare}

**Q:** I see you have PROC TRANSPOSE and PROC SORT.  How come you didn't include
PROC COMPARE?

**A:** There are already several dataset comparison packages in R, such as
[diffdf](https://cran.r-project.org/package=diffdf)
and [comparedf](https://cran.r-project.org/package=compareDF).
The functionality of these packages is also similar to SAS® PROC COMPARE.
If you wish to do dataset comparisons, please research these existing packages.

[top](#top)

****** 

### Are there any other statistics procedures coming? {#other}

**Q:** The `proc_freq()` and `proc_means()` functions are helpful.  But what about
some other stats procedures?  What about PROC GLM and PROC ANOVA?

**A:** These functions are planned for a future release. In the meantime, 
please see the excellent package [sasLM](https://cran.r-project.org/package=sasLM) 
for functions that replicate SAS® statistics related to linear modeling.

[top](#top)

****** 

### How do I get my statistics into a report? {#outputs}

**Q:** I created some frequencies, and need to output them to a report. Is there
a way to create a PDF or RTF directly from the **procs** package?

**A:** Yes.  Put your data frames in a list, and send to `proc_print()`.  You can
use the parameters to assign the titles, the output location, and the output
type. The function supports PDF, RTF, HTML, DOCX, and TXT.  For more advanced
reporting features, see the [reporter](https://reporter.r-sassy.org/) package.

[top](#top)

****** 

### How do I order my frequencies? {#order}

**Q:** The `proc_freq()` function seems to always order the categories alphabetically.
But I have a specific order in mind that is not alphabetical.  Is there a way
to order the frequency categories in a specific way?

**A:** Yes. The `order` parameter on `proc_freq()` allows you to order your
frequencies in four different ways: internal order (the default), data order,
format order, or frequency order.  See the `proc_freq()` documentation on the 
specific keywords needed to control the order.

Also note that if your frequency variable is defined as a factor, the 
`proc_freq()` function will order the frequency categories by that factor.
Here is an example: 
```
library(procs)

# Turn off printing for CRAN checks
options("procs.print" = FALSE)

# Create sample data
df <- as.data.frame(HairEyeColor, stringsAsFactors = FALSE)

# Assign factor for ordering
df$Eye <- factor(df$Eye, c("Green", "Hazel", "Blue", "Brown"))

# Use factor in tables parameter
res <- proc_freq(df,
                 tables = Eye,
                 weight = Freq)

# Output is now ordered by the factor
res
#   VAR   CAT   N CNT      PCT
# 1 Eye Green 592  64 10.81081
# 2 Eye Hazel 592  93 15.70946
# 3 Eye  Blue 592 215 36.31757
# 4 Eye Brown 592 220 37.16216


```

[top](#top)

****** 

<!-- ### Question 2? {#q2} -->

<!-- **Q:** Question here. -->

<!-- **A:** Answer here. -->

<!-- [top](#top) -->

<!-- ****** -->

<!-- ### Question 1? {#q1} -->

<!-- **Q:** Question here. -->


<!-- **A:** Answer here. -->

<!-- [top](#top)  -->

<!-- ****** -->

