[R-SIG-Finance] Linear Regression on data from FRED
josh.m.ulrich at gmail.com
Wed Mar 2 00:19:20 CET 2011
For future reference, this isn't really a finance question and would
be better suited for the R-help list.
There are no columns named "secA" or "secB" in your data.frame "t".
Looking at str(t) probably would have given you enough information to
solve this issue yourself. Since "secA" and "secB" aren't in "t",
lm() has to search for them and finds them in your global environment.
Those objects don't have the same length, hence the error.
You're also doing a lot of unnecessary steps. All you need is:
 "DEXUSEU" "DEXUSUK"
> Data <- merge(DEXUSEU, DEXUSUK, all=FALSE)
> (m <- lm(DEXUSEU ~ DEXUSUK + 0, data=Data))
lm(formula = DEXUSEU ~ DEXUSUK + 0, data = Data)
Joshua Ulrich | FOSS Trading: www.fosstrading.com
On Tue, Mar 1, 2011 at 3:55 PM, Stuart Snell <stuart.snell at gmail.com> wrote:
> I cannot see why the code below produces this error:-
> Error in model.frame.default(formula = secA ~ secB + 0, data = t,
> drop.unused.levels = TRUE) :
> variable lengths differ (found for 'secB')*
> I thought the merge would match up dates in secA and secB, therefore making
> the different lengths of secA and secB irrelevant.
> Any ideas.
> library(quantmod) #for access to FRED
> secA <- getSymbols("DEXUSEU",src="FRED") secB <-
> secA <- zoo(DEXUSEU[,1])
> secB <- zoo(DEXUSUK[,1])
> t.zoo <- merge(secA, secB, all=FALSE)
> t <- as.data.frame(t.zoo)
> cat("Date range is", format(start(t.zoo)), "to", format(end(t.zoo)), "\n")
> m <- lm(secA ~ secB + 0, data=t)
> [[alternative HTML version deleted]]
> R-SIG-Finance at r-project.org mailing list
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance