I don't really have any experience with this but, it looks to me like your creating a view and from that view you want to find the STD and AVG of Factor1. But you say AVG(TableA.Factor1) as Factor1, I don't think TableA would be the table name for DB::table(\DB::raw(" ($subquery) as sub "))
so its not finding Factor1 because its can't find the table. would the table not be called sub.
I have no idea if this is the case or not, but hope it helps, also would've left a comment but I don't have the rep yet :(.