Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

NA in-between values --> False Correlations and Plots?

$
0
0

I have a problem regarding predicting values based on a model under the condition that the values have NA in-between (see code below as an example). As you can see in the plot, the predicted line seems odd and my assumption is: the NA's are kinda "ignored".. Do you perhaps have a solution for this issue?

I'm also running a model through a loop for other value vectors and on their way on looping the correlations between values and predicted values some error messages like "incompatible error" and "invalid factor level, NA generated" appears. So I need a way to ignore the NA in-between...

scale <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
values <- c(2, NA, NA, NA, 30, 45, 60, 75, 85, 100)
mod <- nls(values~(scale)^a, start=list(a=1))
summary(mod)
cor(values, c(predict(mod)))  

plot(scale,values,pch=16)
lines(scale, c(predict(mod),NA,NA,NA), col='blue',lty=2, lwd=3) 


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>