R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

## Defino mi directorio de trabajo
setwd("~/Documents/Estadistica")
##Abriendo paquete pacman
library(pacman)
## El archivo esta en formato SPSS, lo abrimos mediante la libreria haven ## MASS permite analisis discriminante
p_load(haven,dplyr,ggplot2,MASS)
p_load(haven,dplyr,ggplot2,tinytex,tidyr, GGally)
Hombro <- read_sav("Datos hombro.sav")
## Definimos como factor la variable sexoN
Hombro$sexoN <- factor(Hombro$sexoN,
                       levels = c(1, 2), 
                       labels = c("Hombre", "Mujer"))
table (Hombro$sexoN)  ## Frecuencias de sexo
## 
## Hombre  Mujer 
##     50     30
HombroS <- na.omit(Hombro[, c("sexoN", "LMCD","C12CD")])

# Para resumir por sexo la información de Longitud Maxima de clavicula derecha
        
    res_lmcd <- HombroS %>%
          group_by(sexoN) %>%
          summarise(
            n       = sum(!is.na(LMCD)),
            media   = mean(LMCD, na.rm = TRUE),
            sd      = sd(LMCD, na.rm = TRUE)
          ) %>%
          mutate(across(c(media, sd), ~round(.x, 2)))
        res_lmcd
        # Para resumir por sexo la información de Circunferencia media de clavicula derecha
        
      res_C12CD <- HombroS %>%
          group_by(sexoN) %>%
          summarise(
            n       = sum(!is.na(C12CD)),
            media   = mean(C12CD, na.rm = TRUE),
            sd      = sd(C12CD, na.rm = TRUE)
          ) %>%
          mutate(across(c(media, sd), ~round(.x, 2)))
        res_C12CD
          ## Gráfica comparativa
        ggplot(HombroS, aes(x = LMCD, fill = sexoN)) +
          geom_density(alpha = 0.5) +
          labs(
            title = "Gráfica 1. Longitud maxima clavicula derecha por sexo",
            x = "Longitud clavicula derecha por sexo (mm)",
            y = "Densidad"
          ) +
          theme_minimal()

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.