Relative commutator associated with varieties of $n$-nilpotent and of $n$-solvable groups