The central twist of "When Marnie Was There" is the revelation that Marnie is not just a ghost or a figment of Anna's imagination, but is in fact the spirit and memory of Anna's grandmother. The 'Marnie' that Anna interacts with is a younger version from the past, whose experiences Anna is either witnessing supernaturally or reconstructing from stories Marnie told her when she was a baby.
Marnie's life was tragic: neglected by her parents and abused by maids, she found brief happiness with her childhood love, Kazuhiko. They married and had a daughter, Emily. After Kazuhiko's death from illness, a distraught Marnie was institutionalized, and Emily was sent to boarding school, creating a deep rift between them. Emily grew up resentful, eventually ran away, married, and had her own daughter: Anna. Tragically, Emily and her husband were killed in a car accident when Anna was a toddler. The elderly Marnie then took in her granddaughter Anna and cared for her, telling her stories of her own childhood in the Marsh House. However, Marnie herself passed away soon after, leading to Anna being placed in foster care with Yoriko.
This revelation re-contextualizes the entire film. Anna's feeling of familiarity with the Marsh House comes from her own forgotten past. Her intense connection with Marnie is the bond between a grandmother and granddaughter, resurfacing to help Anna heal. The final goodbye at the window is not just a farewell to a friend, but Anna making peace with her lineage and accepting the love of the grandmother she barely knew she had.