---
title: 'R for researchers: Final SalDoc'
date: "April 2015"
---


This article is part of the R for Researchers series.
For a list of topics covered by this series, see the 
[Introduction](RFR_Introduction.html) article. 
If you\'re new to R we highly recommend reading the 
articles in order.


This article has the completed SalDoc.Rmd file.
The material explaining the construction of this table
are contained in the 
[Data presentation](RFR_DataPres.html)
article.

The R chunk options can not be split across multiple lines.
These chunk options extend beyond the display box.
There is a slider bar at the bottom of the display box
which will allow you to scroll to the right to see
the remainder of the content.



```{r echo=FALSE}  
backtick = "`"  
```


* The completed SalDoc.Rmd files should look similar to the following

        ---
        title: "Analysis of Professor Salaries"
        fontsize: 12pt
        geometry: margin=1in
        documentclass: article
        
        output: 
          pdf_document:
            fig_caption: yes
        ---
        
        `r backtick```{r, echo=FALSE}
        targetType <- "latex"
        
        #
        # table numbers
        #
        tabNumRankByDscpl <- 1
        
        #
        # figure numbers
        #
        FigNumYrsFacRank <- 1
        FigNumBoxDscplFacRank <- 2
        FigNumGenYrsFacDscpl <- 3
        FigNumBoxGenRankFacDscpl <- 4
        `r backtick```
        
        `r backtick```{r, echo=FALSE, results="hide", message=FALSE, warning=FALSE, fig.show="hide"}  
        source("SalAnalysis.R")  
        `r backtick```
        
        ## Data overview
    
        
        The Salaries data set is the basis for this analysis.
        It is a sample of academic salaries of Professors at
        United States universities from the 2008-9 school year.
        The salary information was collected to monitor the
        difference in salaries between men and women.
        
        `r backtick```{r, echo=FALSE, results="hide", message=FALSE, warning=FALSE, fig.show="hide"}  
        vars <- colnames(SalariesIn)  
        dscplNames <- levels(salary$dscpl)
        rankNames <- levels(salary$rank)
        `r backtick```

        The data set included `r backtick`r length(salary$salary)` professors.
        The variables included in the data set are 
        `r backtick`r paste(vars[-length(vars)],collapse=", ")`,
        and `r backtick`r vars[length(vars)]`. 
        The sampled professors had ranks of
        `r backtick`r paste(rankNames[-length(rankNames)],collapse=", ")`,
        and `r backtick`r rankNames[length(rankNames)]`
        and were from disciplines 
        `r backtick`r paste(dscplNames[-length(dscplNames)],collapse=", ")`
        and `r backtick`r dscplNames[length(dscplNames)]`.
        The numbers of professors from each of these groups is
        displayed in table `r backtick`r tabNumRankByDscpl`.
        There are about 20 percent more members of discipline B
        included in the sample than of discipline A.
        The table shows there are a greater proportion of Discipline B 
        members with a rank of associate or assistant professor.
        
        `r backtick```{r, echo=FALSE }
        tempTab <- table(salary$rank,salary$dscpl)
        rankByDscpl <- as.data.frame.matrix(tempTab)
        rankByDscpl$Totals <- rowSums(tempTab)
        rankByDscpl["Totals",] <- colSums(rankByDscpl)
        rankByDscpl
        `r backtick```
        
        `r backtick```{r, echo=FALSE, results="asis"}
        xtab <- xtable(rankByDscpl,
                           caption="Count of Professors by discipline and Rank",
                           display=c("s","d","d","d"),
                           align="|r|rr|r|"
                           )
        print(xtab, 
              type=targetType, 
              caption.placement="top", 
              hline.after=c(-1,0,3,4),
              comment=FALSE
              )
        `r backtick```
        
        The relationship between years of service and salary can be
        seen in figure `r backtick`r FigNumYrsFacRank`.
        The panels seem to indicate that for associate and assistant 
        professors most of the members of discipline B have higher 
        salaries than most of the members of discipline A, at the
        same rank.
        The box plots, figure `r backtick`r FigNumBoxDscplFacRank`, also supports 
        this observation.
                
        `r backtick```{r, echo=FALSE, fig.cap="Salaries  by discipline and rank", fig.height=2.75, fig.width=5.5 } 
        plotYrsFacRank
        `r backtick```
                
        `r backtick```{r, echo=FALSE, fig.cap="Salaries summarized by discipline and rank", fig.height=2.75, fig.width=5.5 } 
        boxDscplFacRank
        `r backtick```        
        
        The plots of salaries with color indicators for gender, figure
        `r backtick`r FigNumGenYrsFacDscpl`, indicates there may be a gender
        difference in salary in discipline A.
        The box plots in figure `r backtick`r FigNumBoxGenRankFacDscpl`
        indicate that the difference between the genders in
        discipline A is greatest at the rank of assistant professor.
        
        The plots of salaries with color indicators for gender, figure
        `r backtick`r FigNumGenYrsFacDscpl`, indicates there may be a gender
        difference in salary in discipline A.
        The box plots in figure `r backtick`r FigNumBoxGenRankFacDscpl` indicate
        that the difference between the genders in discipline A is 
        greatest at the rank of assistant professor.
        
        `r backtick```{r, echo=FALSE, fig.cap="Salaries by gender and discipline", fig.height=2.75, fig.width=5.5 } 
        plotYrsFacDscpl
        `r backtick```
        
        `r backtick```{r, echo=FALSE, fig.cap="Salaries summarized by gender and discipline", fig.height=3, fig.width=5.5 } 
        boxGenRankFacDscpl
        `r backtick```


    
    



Return to: [Data presentation](RFR_DataPres.html)

Last Revised: 2/16/2015

    