[R] help with predict and plotting confidence intervals
mwdenslow at yahoo.com
Thu Mar 12 16:14:52 CET 2009
Dear R help,
This seems to be a commonly asked question and I am able to run examples that have been proposed, but I can't seems to get this to work with my own data. Reproducible code is below. Thank you in advance for any help you can provide.
The main problem is that I can not get the confidence lines to plot correctly.
The secondary problem is that predict is not able to find my object when
I include a model object.
## THE DATA
wt.data <- data.frame(code = factor(LETTERS[1:24]),
area = c(60865,480,656792,92298,1200,1490,8202,4000,220,245,4000,390,325,
species = c(673,650,1353,1026,549,536,782,734,516,580,673,560,641,443,1105,
# TRANSFORM AND ADD TO DATAFRAME
wt.data$logA <- log10(wt.data$area)
wt.data$logS <- log10(wt.data$species)
wt.mod <- lm(logS~logA, data = wt.data)
# PLOT THE DATA
with(wt.data,plot(logA,logS, ylim = c(2.3,3.2),xlim = c(0,6)))
abline(wt.mod, lwd = 2)
# create a prediction dataframe the same length as data
pred.frame <- data.frame(a = seq(0,6, length.out = 24))
# error ' object "logA" not found'
# I am not sure why object is not found, I assume this has to do with
# the way I added the transformed variables to the dataframe
pp <- predict(wt.mod, int = "p", newdata=pred.frame)
# runs ok?
pp <- predict(lm(wt.data$logS~wt.data$logA), int = "p", newdata=pred.frame)
# lines are jagged??
# I am not sure how to get the lines to draw correctly here
R version 2.8.1 (2008-12-22)
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
attached base packages:
 stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
I.W. Carpenter Jr. Herbarium [BOON]
Department of Biology
Appalachian State University
Boone, North Carolina U.S.A.
-- AND --
Southeast Regional Network of Expertise and Collections
More information about the R-help