R for researchers: Final SalDoc

April 2015

This article is part of the R for Researchers series. For a list of topics covered by this series, see the Introduction 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 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.

  • 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, echo=FALSE}
      targetType <- "latex"
    
      #
      # table numbers
      #
      tabNumRankByDscpl <- 1
    
      #
      # figure numbers
      #
      FigNumYrsFacRank <- 1
      FigNumBoxDscplFacRank <- 2
      FigNumGenYrsFacDscpl <- 3
      FigNumBoxGenRankFacDscpl <- 4
      ```
    
      ```{r, echo=FALSE, results="hide", message=FALSE, warning=FALSE, fig.show="hide"}  
      source("SalAnalysis.R")  
      ```
    
      ## 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, echo=FALSE, results="hide", message=FALSE, warning=FALSE, fig.show="hide"}  
      vars <- colnames(SalariesIn)  
      dscplNames <- levels(salary$dscpl)
      rankNames <- levels(salary$rank)
      ```
    
      The data set included `r length(salary$salary)` professors.
      The variables included in the data set are 
      `r paste(vars[-length(vars)],collapse=", ")`,
      and `r vars[length(vars)]`. 
      The sampled professors had ranks of
      `r paste(rankNames[-length(rankNames)],collapse=", ")`,
      and `r rankNames[length(rankNames)]`
      and were from disciplines 
      `r paste(dscplNames[-length(dscplNames)],collapse=", ")`
      and `r dscplNames[length(dscplNames)]`.
      The numbers of professors from each of these groups is
      displayed in table `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, echo=FALSE }
      tempTab <- table(salary$rank,salary$dscpl)
      rankByDscpl <- as.data.frame.matrix(tempTab)
      rankByDscpl$Totals <- rowSums(tempTab)
      rankByDscpl["Totals",] <- colSums(rankByDscpl)
      rankByDscpl
      ```
    
      ```{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
            )
      ```
    
      The relationship between years of service and salary can be
      seen in figure `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 FigNumBoxDscplFacRank`, also supports 
      this observation.
    
      ```{r, echo=FALSE, fig.cap="Salaries  by discipline and rank", fig.height=2.75, fig.width=5.5 } 
      plotYrsFacRank
      ```
    
      ```{r, echo=FALSE, fig.cap="Salaries summarized by discipline and rank", fig.height=2.75, fig.width=5.5 } 
      boxDscplFacRank
      ```        
    
      The plots of salaries with color indicators for gender, figure
      `r FigNumGenYrsFacDscpl`, indicates there may be a gender
      difference in salary in discipline A.
      The box plots in figure `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 FigNumGenYrsFacDscpl`, indicates there may be a gender
      difference in salary in discipline A.
      The box plots in figure `r FigNumBoxGenRankFacDscpl` indicate
      that the difference between the genders in discipline A is 
      greatest at the rank of assistant professor.
    
      ```{r, echo=FALSE, fig.cap="Salaries by gender and discipline", fig.height=2.75, fig.width=5.5 } 
      plotYrsFacDscpl
      ```
    
      ```{r, echo=FALSE, fig.cap="Salaries summarized by gender and discipline", fig.height=3, fig.width=5.5 } 
      boxGenRankFacDscpl
      ```

Return to: Data presentation

Last Revised: 2/16/2015