# An Application to SAE with Averaging Pseudo Area Level Model on Sample Dataset

## Load package and data

    library(saePseudo)
    data("dataVill")

## Fitting Model

    result <- avgPseudo(
      prov = dataVill$Area1,
      reg = dataVill$Area2,
      sub = dataVill$Area3,
      vill = dataVill$Area4,
      y = dataVill$ydir_area4,
      x = dataVill$X1,
      var = dataVill$vardir_area4,
      N = dataVill$N,
      method = "REML"
    )

## Extract estimation

### Estimation for Sub-district Area

    result$Est_Area3
    #> # A tibble: 28 × 5
    #> # Groups:   Province, Region [6]
    #>    Province Region Subdistrict y_agr_villsub rse_agr_villsub
    #>       <dbl>  <dbl>       <dbl>         <dbl>           <dbl>
    #>  1        1      1           1          28.9           0.826
    #>  2        1      1           2          25.7           0.764
    #>  3        1      1           3          28.0           0.654
    #>  4        1      2           1          30.1           0.918
    #>  5        1      2           2          31.0           0.872
    #>  6        1      2           3          28.7           1.03
    #>  7        1      2           4          28.1           1.63
    #>  8        1      2           5          28.1           1.15
    #>  9        1      2           6          28.8           0.925
    #> 10        1      3           1          28.2           1.61
    #> # ℹ 18 more rows

### Estimation for Region Area

    result$Est_Area2
    #> # A tibble: 6 × 4
    #> # Groups:   Province [1]
    #>   Province Region y_agr_subreg rse_agr_subreg
    #>      <dbl>  <dbl>        <dbl>          <dbl>
    #> 1        1      1         27.5          0.426
    #> 2        1      2         29.3          0.421
    #> 3        1      3         28.9          0.295
    #> 4        1      4         28.1          0.375
    #> 5        1      5         28.6          0.450
    #> 6        1      6         28.2          0.532

### Estimation for Provincial Area

    result$Est_Area1
    #> # A tibble: 1 × 3
    #>   Province y_agr_regprov rse_agr_regprov
    #>      <dbl>         <dbl>           <dbl>
    #> 1        1          28.5           0.165