---
title: "Introduction to Ssarkartrim Package"
author: "Shouhardyo Sarkar,The University of Iowa,USA"
date: "`Nov 8,2025`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to Ssarkartrim}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Overview

The `Ssarkartrim` package provides a robust trimmed-k mean estimator for numeric data. It is designed to reduce the influence of outliers by removing the `k` smallest and `k` largest values before computing the mean. This vignette walks through installation, usage, and interpretation of the function. 

---

## Installation

To install the package from source:

```r

install.packages("Ssarkartrim_1.0.0.tar.gz", repos = NULL, type = "source")

library(Ssarkartrim)


## Function: `kTrimMean()`


  kTrimMean(dat, k)

 `dat` : A numeric vector.

 `k` : Number of smallest and largest values to trim.

  Returns the trimmed-k mean of the data. If 2k >= length(dat), the function returns    NA with a warning


## Example 1 :


set.seed(5400)

dat <- rexp(20, rate = 0.5)

kTrimMean(dat, k = 2)

## Output

[1] 1.592987

This trims the 2 smallest and 2 largest values from `dat` and computes the mean of the

remaining 16 values.



## Comparison with Mean and Median


mean(dat)

median(dat)

kTrimMean(dat, k = 2)

This shows how `kTrimMean()` provides a middle ground:

`mean()` is sensitive to outliers.

`median()` is robust but may ignore distribution shape.

`kTrimMean()` trims extremes while preserving central tendency.


## Example 2 :


small_dat <- c(1, 2, 3, 100, 200)

kTrimMean(small_dat, k = 1)

This trims the the lowest and largest values


## Edge Case - Example 3:


short_dat <- c(5, 10)

kTrimMean(short_dat, k = 1)


## Output

[1] NA

Warning message:

Not enough data to trim k smallest and largest values.

This shows the function’s built-in safeguard when trimming exceeds available data.


## Use Cases

Robust estimation in small samples

Outlier-resistant summary statistics

Teaching robust statistics in coursework

Comparing estimators in simulation studies


## Package Development Notes

This package was built using:

devtools::create()

Roxygen2 for documentation

document() to generate .Rd files

R CMD build and R CMD check --as-cran for validation

Rd2pdf to generate the manual

usethis::use_vignette() to create this vignette


## Author

Shouhardyo Sarkar, 

Department of Statistics and Actuarial Science,

Schaeffer Hall, Iowa City , IA 52240

The University of Iowa,USA 

Email: shouhardyo-sarkar@uiowa.edu


## Conclusion

The Ssarkartrim package offers a simple, reproducible, and pedagogically useful implementation of the trimmed-k mean.  
