No subject
Faheem Mitha
faheem at email.unc.edu
Sun Feb 27 06:53:15 CET 2000
Dear R people,
Here is a little script. There is a problem with the function plot.factor,
which is puzzling. I wrote a very similar code for a one-way model and it
worked fine. With the code below, I get the mysterious error message
Error in barplot.default(table(x), axisnames = axisnames, ...) : `height'
must be a vector or a matrix
I was told the problem was likely connected to the fact that I had not
coerced my factors to be factor objects, but I did so and it still
doesn't work. I have not included the file hkepd.dat from which the data
is read. I think that it is possible the error will be visible from the
code below. If not, I can certainly send out the data file if anybody
wants to use it. I would be grateful if anyone would tell me how to
correct the fault.
The linear model below is of the form hosp ~ s*pollut. `hosp' is hospital
admissions data, `s' is the season to which the data belongs, and `pollut'
is the level of so2 pollution.
Sincerely, Faheem Mitha.
*****************************************************************************
hk.df <- read.table("hkepd.dat",header=T, row.names=NULL)
attach(hk.df)
# making a function `season' to convert season data (months. years, into
# season factors (spring, summer, autumn, winter).
season <- function(m,d)
{
if ( m == 1 || m == 2 || ( m == 12 && d >= 21) || (m == 3 && d <= 20 ) )
return("wi")
else if
( m == 4 || m == 5 || ( m == 3 && d >= 21) ||(m == 6 && d <= 20 ) )
return("sp")
else if
( m == 7 || m == 8 || ( m == 6 && d >= 21) ||(m == 9 && d <= 20 ))
return("su")
else if
( m == 10 || m == 11 || ( m == 9 && d >= 21) || (m == 12 && d <= 20 ) )
return("au")
else
return("error")
}
#making season factor vector
s <- 1:length(month)
for(i in 1:length(month))
s[i] <- season(month[i],day[i])
# reading columns of the data frame to vectors
hosp <- Total
so <- so2
#stuff to make pollut factor vector
pollut <- rep("high",length(so))
pollut[so <= 21.62] <- "med"
pollut[so <= 14.23] <- "low"
# coercing season and pollut vectors to be factors.
sf <- factor(s)
pollutf <- factor(pollut)
# making data frame to do the two way model
poll.df <- data.frame(hosp,s,pollut)
attach(poll.df)
pollf.df <- data.frame(hosp,sf,pollutf)
attach(pollf.df)
# trying to get plot.factor to do its stuff. Fails with error message
# quoted above.
postscript("poll.anova1.ps",width=5.5, height = 5, horizontal=F, pointsize=8)
par(mfrow=c(2,2),mar=c(5,3,3,1)+0.1)
plot.factor(pollf.df)
dev.off()
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list