Hi all,
I have an issue with running a linear model. It used to work fine
and as with other repetitive tasks I have saved the steps and code.
Below are the steps used (had no problem with previous version fo
Deducer)
+++++++++++++++++++
Add data set as tab or cvs format.
Go to:
·
Analysis
·
Linear Model
·
Add Fc as outcome
·
FA or Ear as Factor
·
Click continue
·
Click continue
·
Click EXPORT button on right
·
Check Predicted box
·
Click RUN
The data Viewer will have a new column inserted Predicted
Note this is
not the completed model.
Copy and
paste the code below in the Console window.
Make sure to edit Predicted on 5th line so it
is labeled in
data Viewer table.
model.lm <- lm(formula=FCmin ~
FA,data=Bats,na.action=na.omit)
Anova(model.lm,type='II')
summary(model.lm)
tmp<-predict(model.lm,Bats)
Bats[names(tmp),"Fcmin_predicted"]<-tmp
rm('tmp')
rm('model.lm')
This will provide predicted values.
+++++++++++++++++++++++
This is not working.
Data set is very simple:
I only needed to "Predict" the Fc for the first row that is not
available.
as an FYI the
Variable view
SPEC_CODE Character
FA Double
Fc Double
| SPEC_CODE |
FA |
Fc |
| Lasatr |
46.3 |
|
| Lasblo |
40 |
43 |
| Lasbor |
40.5 |
40.6 |
| Lascas |
44.5 |
30.72 |
| Lascin |
53.5 |
21 |
| Lasega |
45 |
31.4 |
| Lasint |
53 |
30.8 |
| Lassem |
53.5 |
40.35 |
Here is paste from console when I complete the above first steps.
No predicted value is added tot he data frame as it has been in the
past.
Seems to be some error as the goal is to predict the missing value
and the notice NAs are not allowed...is puzzling???
> Lasiurus2 <- dget('E:/Acoustic Parameters/Predicted and
genera summaries/Vespertilionids/Lasiurus/Lasiurus2.robj')
> Bats<-Lasiurus2
>
Error in text.default(x, y,
labels.id[ind], cex =
cex.id, xpd =
TRUE, :
invalid 'pos' value
In addition: Warning message:
not plotting observations with leverage one:
1, 2, 3, 5, 6
Error in plot.lm(.gui.working.env$model.lm, c(1, 4, 3, 5),
sub.caption = "") :
NAs are not allowed in subscripted assignments
In addition: Warning messages:
1: not plotting observations with leverage one:
1, 2, 3, 5, 6
2: not plotting observations with leverage one:
1, 2, 3, 5, 6
model.lm <- lm(formula=Fc ~
as.factor(FA),data=Bats,na.action=na.omit)
> Anova(model.lm,type='II')
Anova Table (Type II tests)
Response: Fc
Sum Sq Df F value Pr(>F)
as.factor(FA) 174.43 5 0.1863 0.9317
Residuals 187.21 1
> summarylm(model.lm)
Call:
lm(formula = Fc ~ as.factor(FA), data = Bats, na.action = na.omit)
Residuals:
2 3 4 5 6 7
-2.389e-15 -7.562e-18 -1.818e-17 -9.675e+00 9.392e-16 1.010e-15
8
9.675e+00
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 43.00 13.68 3.143 0.196
as.factor(FA)40.5 -2.40 19.35 -0.124 0.921
as.factor(FA)44.5 -12.28 19.35 -0.635 0.640
as.factor(FA)45 -11.60 19.35 -0.599 0.656
as.factor(FA)53 -12.20 19.35 -0.630 0.642
as.factor(FA)53.5 -12.32 16.76 -0.735 0.596
Residual standard error: 13.68 on 1 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.4823, Adjusted R-squared: -2.106
F-statistic: 0.1863 on 5 and 1 DF, p-value: 0.9317
> Bats[["predicted.link"]] <- predict(model.lm, newdata=Bats)
Error in model.frame.default(Terms, newdata, na.action = na.action,
xlev = object$xlevels) :
factor as.factor(FA) has new levels 46.3
> rm('model.lm')
>
So what am I now doing incorrectly?
Seems no point in pasting the second step of code since the
"Predicted" values are no created.
Bruce