I am trying to write a polynomial function between two columns of my data frame.
Inside of these two columns I have grouped rows named Group1
and Group2
.
I want to fit these groups R
~V
values using
fit_all <- summary(lm(R ~ poly(V,2,raw=TRUE), data = df, subset = state))
but I am getting warning message which says
In summary.lm(lm(R ~ poly(V, 2, raw = TRUE), data = df_rep, subset = state)) : essentially perfect fit: summary may be unreliable
I check this error which might be related NA values. Since I don't have NA values neither in my real data nor df
data I am stuck at this point.
finally for each Group1
and Group2
I want to extract coefficients
for each group fittings.
Please take a look my reproducible example
set.seed(1)
No <- rep(seq(1,4,1),each=21)
AC <- rep(rep(c(78,110),each=1),times=length(No)/2)
state <- rep(rep(c("Group 1","Group 2"),2),each=21)
V <- rep(seq(100,2100,100),times=4)
R = sort(replicate(4, sample(5000:6000,21)))
df <- data.frame(No,AC,V,R,state)
head(df)
No AC V R state
1 1 78 100 5004 Group 1
2 1 110 200 5014 Group 1
3 1 78 300 5030 Group 1
4 1 110 400 5039 Group 1
5 1 78 500 5057 Group 1
6 1 110 600 5068 Group 1