user2543601 user2543601 - 4 months ago 13
R Question

Linear Regression in R Making Every Record a Regressor

I'm trying to make a linear regression using the lm() function in R. When I run it, it appears that R is taking each record and making it an independent variable.

fit3 <- lm(no_outliers$strat_count ~ no_outliers$CDS_emerg + no_outliers$weighted_volume_avg)
summary(fit3)


This is a sample of the output (there are 118 independent variables, but I didn't want to put all of it on the post):

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -336.1017 1065.5530 -0.315 0.7652
no_outliers$weighted_volume_avg941931862 12.2047 31.2349 0.391 0.7121
no_outliers$weighted_volume_avg949989365.5 4.0453 33.3295 0.121 0.9081
no_outliers$weighted_volume_avg955100055.4 10.4469 31.3577 0.333 0.7525
no_outliers$weighted_volume_avg961033059.1 -17.2295 32.3160 -0.533 0.6168
no_outliers$weighted_volume_avg973785580 85.1891 40.0488 2.127 0.0867 .
no_outliers$weighted_volume_avg976666189.1 48.1133 39.9253 1.205 0.2821
no_outliers$weighted_volume_avg979529996 26.2521 31.2707 0.840 0.4395
no_outliers$weighted_volume_avg985701661.4 35.3185 35.8381 0.986 0.3696
no_outliers$weighted_volume_avg988019226.8 66.4781 31.3502 2.120 0.0875 .
no_outliers$weighted_volume_avg994324495.5 -13.4227 32.9220 -0.408 0.7004
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 29.2 on 5 degrees of freedom
Multiple R-squared: 0.9752, Adjusted R-squared: 0.3894
F-statistic: 1.665 on 118 and 5 DF, p-value: 0.3005


Any help or pointers would be greatly appreciated.

Answer

I guess weighted_volume_avg is a factor. Try class(no_outliers$weighted_volume_avg). If it is should to convert it to numeric first. Try:

no_outliers$weighted_volume_avg <- as.numeric(as.character(no_outliers$weighted_volume_avg))

Then try your lm again.

Comments