We consider a weighted homogeneous germ of complex analytic variety (X, 0) ⊂ (ℂn, 0) and a function germ f : (ℂn, 0) → (ℂ, 0). We derive necessary and sufficient conditions for some deformations to have non-negative degree (i.e., for any additional term in the deformation, the weighted degree is not smaller) in terms of an adapted version of the relative Milnor number. We study the cases where (X, 0) is an isolated hypersurface singularity and the invariant is the Bruce-Roberts number of f with respect to (X, 0), and where (X, 0) is an isolated complete intersection or a curve singularity and the invariant is the Milnor number of the germ f: (X, 0) → ℂ. In the last part, we give some formulas for the invariants in terms of the weights and the degrees of the polynomials.