[R] How to apply a function to every element of a dataframe, when the function uses for each colummn and row different values to calculate with?
peter dalgaard
pdalgd at gmail.com
Wed Aug 21 08:47:46 CEST 2013
On Aug 21, 2013, at 00:01 , David Winsemius wrote:
>
> fmat <- (abs(x - E) )^2/E
>
> (I'm not sure why that abs is in the `chisq.test` code.)
A bit of a misquote there; chisq.test has
STATISTIC <- sum((abs(x - E) - YATES)^2/E)
The abs() ensures that the Yates correction is towards zero.
(a few lines above, we have
YATES <- min(0.5, abs(x - E))
which avoids the embarrassment of a positive chi-square when x==E).
If YATES==0, he squaring of course makes abs() superfluous.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list