How to downweigh outlier in a sum? I have a simple problem.
Assume following dataset:
resids <- c(,9,8,7,12,14,8,9,15,4,9,10,200)
n <- length(resids)
p <- 2

Using this dataset I want to estimate:
Phi.P <- sum(resids^2)/(n-p) 

We see that the variable 'resids' contain an outlier with value 200. This outlier will cause the estimate of Phi.P to be too high. So I used a robust estimator based on the median:
Phi.P <- median(resids^2)*(n/(n-p))

This works OK but not extremely good. Therefore I am looking for a way do downweight the outlier in sum(resids^2). Does anybode know how to do this? 
 A: I don't understand exactly what do you want estimate. If you want approximative value of the variable 'resids' or value of sum(resids^2)/(n-p) and I don't know why you use this variable 'p'.
But if you want estimate the approximative value of 'resids', you can use the geometric mean, it works well even if your numerical vector ('resids') contains an outlier as we can see in this example below:
# Geometric mean function
fGeometric <- function(x) {
  n <- length(x)
  Moy <- prod(x)^(1/n)
  return(Moy)
}

resids <- c(1,4,3,2,5,3,1,6, 4, 990)

fGeometric(resids)

[1] 4.934179

**********************************************************
# An other values of the numerical vector for example:

resids<-c(16,9,8,7,12,14,8,9,15,4,9,10,1257)

fGeometric(resids)

[1] 13.8061

Hope it can help you...;-)
A: One problem with the median is that it's not a smooth function, which can make optimizing things difficult. Several alternative robust estimates are available Tukey's bisquare and the huber loss function are both popular. You may also want to consider a trimmed mean.
From the syntax in your post it looks like you are using R. In R, the trimmed mean is implemented as mean(trim=). The other two I mentioned are implemented in the robust package in robust::psi.weight.
