# Start with your own repeated-trait data

Download `own_data_starter.R` into your analysis folder. It uses base R, reads
your CSV, checks its structure, and returns a prepared long data frame and an
audit. It does not fit models or change your original CSV.

Your CSV should have one row per individual, recorded occasion, and trait:

| animal_id | visit | trait | value | temperature |
|---|---|---|---:|---:|
| bird_1 | first | boldness | 2.3 | 15 |
| bird_1 | first | activity | 4.1 | 15 |
| bird_1 | first | exploration | 1.2 | 15 |
| bird_1 | first | aggression | 0.6 | 15 |
| bird_1 | second | boldness | 2.8 | 18 |

This is a layout illustration, not enough observations to fit a model. Include
the remaining traits and repeated occasions for your individuals. A visit label
such as `first` may repeat across individuals: the script combines the individual
and visit into a globally unique occasion key. Use a recorded period that makes
biological sense for joint trait measurements. If individuals are numbered anew
within each site, first create a globally unique individual identifier.

In R, run:

```r
source("own_data_starter.R")
prepared <- prepare_own_data(
  csv_path = "my_traits.csv",
  individual_col = "animal_id", occasion_col = "visit",
  trait_col = "trait", value_col = "value",
  traits = c("boldness", "activity", "exploration", "aggression"),
  predictor_cols = "temperature", # character() when there are no predictors
  missing = "stop", standardise = TRUE
)
my_long <- prepared$data
head(my_long)
prepared$trait_audit
prepared$repeats
prepared$scaling
```

Replace the file path and column names with yours. Trait names must exactly match
the values in your trait column; their specified order becomes the matrix order.
For categorical predictors, choose factors and their reference levels explicitly
after preparation. For example, `my_long$sex <- factor(my_long$sex,
levels = c("female", "male"))` applies only if you included a `sex` predictor with
those labels. Check the spelling and levels against your original data first.

The script stops on duplicate individual–occasion–trait rows, missing identifiers,
text in the numeric response column, infinite values, constant retained traits,
or a lack of repeated structure. Predictors must be constant across trait rows
within an occasion. It reports missing values and absent trait rows separately.
It retains single-occasion individuals with a warning when other individuals do
have repeats, and reports the full retained repeat distribution.

Incomplete occasions stop the default run. After deciding whether a complete-case
analysis addresses your question, you can explicitly choose
`missing = "complete_occasions"`. This removes an entire occasion if any selected
trait or predictor is missing. It is a deliberately simple starting route; it does
not model missingness or support claims that the retained sample is representative.
Do not replace a missing value with zero. For partially observed response models,
choose and document an appropriate likelihood workflow separately.

Standardisation is performed separately for each trait on the retained rows. The
means and standard deviations are saved so you can explain the response scale.
It does not make bounded, censored, or strongly non-Gaussian data Gaussian. Apply
scientifically justified transformations before this step and retain their code.

The output has `value`, `trait`, `individual`, and `occasion` columns, ready to
replace the corresponding long data frame in the tutorial's model formulas.
Keep the model's mean predictors aligned with the columns you prepared. A
rank-one-plus-unique structure is not automatically identifiable for every trait
count; read the rank lesson before choosing a rank for your own response set. The audit does
not establish sufficient sample size or model adequacy. Continue with fitting,
fit-object diagnostics, and uncertainty before interpreting estimates.

To run from a terminal, edit `settings` near the top of the R script and use:

```sh
Rscript own_data_starter.R my_traits.csv
```

This writes `own-data-prepared/` in your current directory, including a
`prepared.rds` file that preserves factor levels and five readable audit/data
CSVs. It refuses to overwrite an existing output folder. Keep these local outputs
under your own data-sharing permissions; the script does not upload anything.
