Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在r中使用Predict.lm反转回归 我在DATAFAFRAML CalvByRuno 1中有一些数据,这些变量具有标称和PAR,它们代表了使用特定分析技术对一组标准的分析发现的峰面积比(PAR),以及两个LM模型的数据(线性和二次)的关系。我尝试使用Time.LM函数来计算标称值,考虑到我的PAR值,但是两个预测值LM和拟合似乎只给了我PAR值。我正在慢慢失去我的魔力,有人能帮忙吗_R_Statistics - Fatal编程技术网

如何在r中使用Predict.lm反转回归 我在DATAFAFRAML CalvByRuno 1中有一些数据,这些变量具有标称和PAR,它们代表了使用特定分析技术对一组标准的分析发现的峰面积比(PAR),以及两个LM模型的数据(线性和二次)的关系。我尝试使用Time.LM函数来计算标称值,考虑到我的PAR值,但是两个预测值LM和拟合似乎只给了我PAR值。我正在慢慢失去我的魔力,有人能帮忙吗

如何在r中使用Predict.lm反转回归 我在DATAFAFRAML CalvByRuno 1中有一些数据,这些变量具有标称和PAR,它们代表了使用特定分析技术对一组标准的分析发现的峰面积比(PAR),以及两个LM模型的数据(线性和二次)的关系。我尝试使用Time.LM函数来计算标称值,考虑到我的PAR值,但是两个预测值LM和拟合似乎只给了我PAR值。我正在慢慢失去我的魔力,有人能帮忙吗,r,statistics,R,Statistics,calvarbyruno.1数据帧 structure(list(Nominal = c(1, 3, 6, 10, 30, 50, 150, 250), Run = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), PAR = c(1.25000000000000e-05, 0.000960333333333333, 0.0020583333333333

calvarbyruno.1数据帧

structure(list(Nominal = c(1, 3, 6, 10, 30, 50, 150, 250), Run = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    PAR = c(1.25000000000000e-05, 0.000960333333333333, 0.00205833333333334, 
    0.00423333333333333, 0.0322333333333334, 0.614433333333334, 
    1.24333333333333, 1.86333333333333), PredLin = c(-0.0119152187070942, 
    0.00375925114245899, 0.0272709559167888, 0.0586198956158952, 
    0.215364594111427, 0.372109292606959, 1.15583278508462, 1.93955627756228
    ), PredQuad = c(-0.0615895732702735, -0.0501563307416599, 
    -0.0330831368244257, -0.0104619953693943, 0.100190275883806, 
    0.20675348710041, 0.6782336426345, 1.04748729725370)), .Names = c("Nominal", 
"Run", "PAR", "PredLin", "PredQuad"), row.names = c(NA, 8L), class = "data.frame")
线性模型

summary(callin.1)

Call:
lm(formula = PAR ~ Nominal, data = calvarbyruno.1, weights = Nominal^calweight)

Residuals:
       Min         1Q     Median         3Q        Max 
-0.0041172 -0.0037785 -0.0003605  0.0024465  0.0071815 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)  
(Intercept) -0.007083   0.005037  -1.406   0.2093  
Nominal      0.005249   0.001910   2.748   0.0334 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 0.004517 on 6 degrees of freedom
Multiple R-squared: 0.5572,     Adjusted R-squared: 0.4835 
F-statistic: 7.551 on 1 and 6 DF,  p-value: 0.03338 
二次模型

> summary(calquad.1)

Call:
lm(formula = PAR ~ Nominal + I(Nominal^2), data = calvarbyruno.1)

Residuals:
        1         2         3         4         5         6         7         8 
 0.053366  0.033186  0.002766 -0.036756 -0.211640  0.177012 -0.021801  0.003867 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)   
(Intercept)  -6.395e-02  6.578e-02  -0.972  0.37560   
Nominal       1.061e-02  2.205e-03   4.812  0.00483 **
I(Nominal^2) -1.167e-05  9.000e-06  -1.297  0.25138   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 0.128 on 5 degrees of freedom
Multiple R-squared: 0.9774,     Adjusted R-squared: 0.9684 
F-statistic: 108.2 on 2 and 5 DF,  p-value: 7.658e-05
但是Predict给了我这些值,这两个值似乎都是错误的(尽管我不能计算出第二组的不同之处是什么

> predict(callin.1)
           1            2            3            4            5            6 
-0.001834123  0.008663451  0.024409812  0.045404959  0.150380698  0.255356437 
           7            8 
 0.780235132  1.305113826 
> predict(callin.1,type="terms")
      Nominal
1 -0.32280040
2 -0.31230282
3 -0.29655646
4 -0.27556131
5 -0.17058558
6 -0.06560984
7  0.45926886
8  0.98414755
attr(,"constant")
[1] 0.3209663
编辑:正如已经指出的,我还不是很清楚我想要实现什么,所以我会试着更好地检验自己

数据来自一组已知浓度(标称)标准的分析,该标准给出了一组特定的响应,或峰面积比(PAR)。我想展示哪个模型最适合该数据,然后使用该模型分析未知样品以确定其浓度

我正试图跟踪其他为此工作的人,这涉及;
a)找到合适的权重,通过找到PAR的运行内方差,并将其拟合到对数模型(方差(PAR))=A+Blog(标称),其中B将是使用的权重(舍入到最近的整数)
b) 将每次运行的数据拟合到线性模型(PAR=a+b名义)和二次模型(PAR=a+b名义+C名义^2)
c) 反算各标准品的发现浓度,并与标称浓度进行比较,得出偏差
d) 评估整个校准范围内的偏差,并根据偏差选择模型


这个问题正试图解决c)。在R邮件列表上的帖子表明,仅仅用相反的术语进行回归是不合适的,我可以手动为线性模型进行计算,但我正在为二次模型而挣扎。仔细查看R邮件列表,似乎其他人也想做同样的事情。

好的,我实际上不得不尝试一下,在看了各种东西之后,我写了一个函数来找到二次方程的根

invquad<-function(a,b,c,y,roots="both", xmin=(-Inf), xmax=(Inf),na.rm=FALSE){
#Calculate the inverse of a quadratic function y=ax^2+bx+c (ie find x when given y)
#Gives NaN with non real solutions
root1<-sqrt((y-(c-b^2/(4*a)))/a)-(b/(2*a))
root2<--sqrt((y-(c-b^2/(4*a)))/a)-(b/(2*a))
if (roots=="both") {
    root1<-ifelse(root1<xmin,NA,root1)  
    root1<-ifelse(root1>xmax,NA,root1)  
    root2<-ifelse(root2<xmin,NA,root2)  
    root2<-ifelse(root2>xmax,NA,root2)      
    result<-c(root1,root2)
    if (na.rm) result<-ifelse(is.na(root1),root2, result)
    if (na.rm) result<-ifelse(is.na(root2),root1,result)
    if (na.rm) result<-ifelse(is.na(root1)&is.na(root2),NA,result)
},roots="both"
if (roots=="min")
    result<-pmin(root1,root2, NA.rm=TRUE)
if (roots=="max")
    result<-pmax(root1,root2, NA.rm=TRUE)
result
}
我们可以做分析,找到系数,然后找到反比,使用一些我们期望的标称值的合理极限

lm(PAR~Nominal+I(Nominal^2))->bob
> bob[[1]][[3]]
[1] -1.166904e-05 # Nominal^2
> bob[[1]][[2]]
[1] 0.01061094 # Nominal
> bob[[1]][[1]]
[1] -0.06395298 # Intercept
> invquad(bob[[1]][[3]],bob[[1]][[2]],bob[[1]][[1]],y=PAR,xmin=-0.2,xmax=300,na.rm=TRUE)
[1]   6.068762   6.159306   6.264217   6.472106   9.157041  69.198703 146.949154
[8] 250.811211

希望这有帮助……

好的,我实际上不得不尝试一下,在看了各种东西之后,我写了一个函数来找到二次方程的根

invquad<-function(a,b,c,y,roots="both", xmin=(-Inf), xmax=(Inf),na.rm=FALSE){
#Calculate the inverse of a quadratic function y=ax^2+bx+c (ie find x when given y)
#Gives NaN with non real solutions
root1<-sqrt((y-(c-b^2/(4*a)))/a)-(b/(2*a))
root2<--sqrt((y-(c-b^2/(4*a)))/a)-(b/(2*a))
if (roots=="both") {
    root1<-ifelse(root1<xmin,NA,root1)  
    root1<-ifelse(root1>xmax,NA,root1)  
    root2<-ifelse(root2<xmin,NA,root2)  
    root2<-ifelse(root2>xmax,NA,root2)      
    result<-c(root1,root2)
    if (na.rm) result<-ifelse(is.na(root1),root2, result)
    if (na.rm) result<-ifelse(is.na(root2),root1,result)
    if (na.rm) result<-ifelse(is.na(root1)&is.na(root2),NA,result)
},roots="both"
if (roots=="min")
    result<-pmin(root1,root2, NA.rm=TRUE)
if (roots=="max")
    result<-pmax(root1,root2, NA.rm=TRUE)
result
}
我们可以做分析,找到系数,然后找到反比,使用一些我们期望的标称值的合理极限

lm(PAR~Nominal+I(Nominal^2))->bob
> bob[[1]][[3]]
[1] -1.166904e-05 # Nominal^2
> bob[[1]][[2]]
[1] 0.01061094 # Nominal
> bob[[1]][[1]]
[1] -0.06395298 # Intercept
> invquad(bob[[1]][[3]],bob[[1]][[2]],bob[[1]][[1]],y=PAR,xmin=-0.2,xmax=300,na.rm=TRUE)
[1]   6.068762   6.159306   6.264217   6.472106   9.157041  69.198703 146.949154
[8] 250.811211

希望这有帮助……

我假设您正在寻找预测标称值,线性mdoel的预测标称值为1.351781、1.532355、1.7841538。。。118.406617, 238.219915, 356.337652. 我可以用手做线性和,不知道如何在R中做它。如果你试图预测从PAR的名义,为什么不是你的线性回归<代码> LM(标称-PAR)< /代码>?我想基于标称CONC(对于线性和二次模型)来模拟PAR,但是,我也想回计算CONC的值,这就是我所坚持的。我承认用另一种方法进行回归会更容易。这对我来说没有多大意义-你模型的假设是名义浓度的测量没有误差。你为什么要用有错误的东西来预测没有错误的东西?我已经稍微编辑了这个问题,以扩展我试图实现的目标,我有点迷失了,所以如果解释不好,请原谅我。我将查看下面建议的软件包。我假设您正在查找预测标称值,线性mdoel的预测标称值将为1.351781、1.532355、1.7841538。。。118.406617, 238.219915, 356.337652. 我可以用手做线性和,不知道如何在R中做它。如果你试图预测从PAR的名义,为什么不是你的线性回归<代码> LM(标称-PAR)< /代码>?我想基于标称CONC(对于线性和二次模型)来模拟PAR,但是,我也想回计算CONC的值,这就是我所坚持的。我承认用另一种方法进行回归会更容易。这对我来说没有多大意义-你模型的假设是名义浓度的测量没有误差。你为什么要用有错误的东西来预测没有错误的东西?我已经稍微编辑了这个问题,以扩展我试图实现的目标,我有点迷失了,所以如果解释不好,请原谅我。我将查看下面建议的软件包。