J.Pop
J.Pop

Reputation: 35

lm Regression problems

I am doing a simple regression where I want to explain the return of an asset with RF (Risk Free Rate) and MRP (Market Risk Premium). I extracted all data from excel files and coerced them in a data.frame. Since lm demanded the data type to be a data.frame.

Now I got 320 rows and 3 columns in a data frame. But the regression still won't work. I also get a lot of coefficients, instead of just 3.

My code:

dataset <- data.frame(rets[,1],RF,MRP)
lm(formular=rets...2.~RF + Mkt.RF, data=dataset)

In the lm formular I put the exact names of the header of each column.

Oh, ignore that RF and MRP are in percent. That has to be changed of course.

Output: enter image description here

Upvotes: 0

Views: 88

Answers (1)

N.Clarke
N.Clarke

Reputation: 268

It looks like your variables RF and Mtk.RF are read as categorical variables, instead of numeric ones. That's why there are many coefficients (one for each 'category'). Try these and fit the lm function again.

dataset$RF <- as.numeric(dataset$RF)
dataset$Mtk.RF <- as.numeric(dataset$Mtk.RF)

Upvotes: 1

Related Questions