Skip to content

linear regression

4 messages · maggy yan, Steven Kennedy, Dennis Murphy +1 more

#
your dataframe needs to be called "Nord". If it is not, then replace
"Nord" with the actual name of your dataframe
On Sat, Aug 13, 2011 at 10:43 PM, maggy yan <kiotoqq at googlemail.com> wrote:
#
Hi:

Try something like this, using dat as the name of your data frame:

xyplot(PM10 ~ Ref | WR, data = dat, type = c('p', 'r'))

The plot looks silly with the data snippet you provided, but should
hopefully look more sensible with the complete data. The code creates
a four panel plot, one per direction, with points and a least squares
regression line fit in each panel. The regression line is specific to
a data subset, not the entire data frame.

HTH,
Dennis
On Sat, Aug 13, 2011 at 5:43 AM, maggy yan <kiotoqq at googlemail.com> wrote:
#
Don't forget to load `lattice` package. `latticeExtra` with
`panel.ablineeq` can be also helpful.

This was however for plotting. For subset regression by each WR without
plotting you'd use something like `lapply` or `sapply`.

ans <- sapply(unique(data$WR), function(dir) {
    out <- list(lm(PM10~Ref, subset(data, WR=dir)))
    names(out) <- dir
    out
})

`ans$West` will return one of the results.

There are many ways to skin a cat. Perhaps it was not the best one.

Mikhail
On 08/13/2011 11:30 AM, Dennis Murphy wrote: