statistics - R-sq values, linear regression of several trends within one dataset -
i running sticky spot trying solve variance accounted trend several times within single info set.....
my info structured this
x <- read.table(text = " sta year value 1968 457 1970 565 1972 489 1974 500 1976 700 1978 650 1980 659 b 1968 457 b 1970 565 b 1972 350 b 1974 544 b 1976 678 b 1978 650 b 1980 690 c 1968 457 c 1970 565 c 1972 500 c 1974 600 c 1976 678 c 1978 670 c 1980 750 " , header = t)
and trying homecoming this
sta r-sq n1 b n2 c n3
where n# corresponding r-squared value of locations info in original set....
i have tried
fit <- lm(value ~ year + sta, info = x)
to give model of yearly trend of value each individual station on years info available value, within master info set....
any help appreciated.... stumped on 1 , know familiarity r problem.
to r-squared value
~ year
each grouping of sta
, can take previous answer, modify , plug-in values:
# assuming x info frame (make sure don't have hmisc loaded, interfere) models_x <- dlply(x, "sta", function(df) summary(lm(value ~ year, info = df))) # extract r.squared values rsqds <- ldply(1:length(models_x), function(x) models_x[[x]]$r.squared) # give names rows , col rownames(rsqds) <- unique(x$sta) colnames(rsqds) <- "rsq" # have rsqds rsq 0.6286064 b 0.5450413 c 0.8806604
edit: next mnel's suggestion here more efficient ways r-squared values nice table (no need add together row , col names):
# starting models_x above rsqds <- data.frame(rsq =sapply(models_x, '[[', 'r.squared')) # starting original info in x, great: rsqds <- ddply(x, "sta", summarize, rsq = summary(lm(value ~ year))$r.squared) sta rsq 1 0.6286064 2 b 0.5450413 3 c 0.8806604
r statistics linear-regression