Something this complex I'd probably just run through the DB facade, though I can't test if it'd actually work for you:
$sql = <<< EOF
SELECT
c.location_id, ROUND(((@rank - rank) / @rank), 2) AS percentile_rank
FROM
(SELECT
*,
@prev:=@curr,
@curr:=CAST(a.value AS unsigned) AS transformed,
@rank:=IF(@prev = @curr, @rank, @rank + 1) AS rank
FROM
(SELECT id, attribute_id, location_id, value FROM attributes_locations) AS a,
(SELECT @curr:= null, @prev:= null, @rank:= 0 ) AS b
WHERE a.attribute_id = 4
AND a.location_id IS NOT NULL
ORDER BY transformed DESC) AS c
HAVING percentile_rank >= 0.75;
EOF;
$results = DB::select($sql);