微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R向量计算不正确的zscore

如何解决R向量计算不正确的zscore

我有一个类似以下的数据集:

func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView?
    {
         if (annotation is MapEarthquakeAnnotation) {
             let mapEqAnnotation = annotation as! MapEarthquakeAnnotation
             var view: MKPinAnnotationView
            print("MARIOCASH",Int(sliderTime.value))
             if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: mapEqAnnotation.identifier) as? MKPinAnnotationView
             {
                 // Recycle old view
                 dequeuedView.annotation = annotation
                 view = dequeuedView
             }
             else
             {
                
                 // Create new view
                
                view = MKPinAnnotationView(annotation: annotation,reuseIdentifier: mapEqAnnotation.identifier)
                view.canShowCallout = true
                view.pinTintColor = UIColor.brown
                 
                 let infoButton = UIButton(type: .infoDark)
                 infoButton.addTarget(self,action: #selector(infoButtonClicked(_:)),for: .touchUpInside)
                 view.rightCalloutAccessoryView = infoButton
             }
             return view
        }else if annotation is MapSeismometerannotation
        {
            if let annotation = annotation as? MapSeismometerannotation
            {
                var view: MKPinAnnotationView
                /*
                // Recycle old view
                if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: annotation.identifier) as? MKPinAnnotationView
                {
                    dequeuedView.annotation = annotation
                    view = dequeuedView
                }
                else
                { */
                    // Create new view
                    view = MKPinAnnotationView(annotation: annotation,reuseIdentifier: annotation.identifier)
                    view.canShowCallout = true
                    view.pinTintColor = UIColor.green
                    view.image = UIImage(named: "pin-verde")
                    if annotation.identifier == "redpin"
                    {
                        var count = 0
                        var c = 0.8 //valore iniziale dell'aplha per l'opacità del pin rosso
                        view.image = UIImage(named: "pin-rosso")
                        Timer.scheduledTimer(withTimeInterval: 1,repeats: true)
                        {t in //ogni secondo questo timer cambia il valore dell'alpha del pin che sta vibrando
                            view.alpha = CGFloat(c)
                            count += 1
                            c -= 0.15
                            if count == 5
                            {
                                t.invalidate()
                            }
                        }
                    }
                return view
                //}
            }
            return nil
        }
        return nil
    }

我已经为此数据集计算了均值和sd

> Pricing
   ID Paper Type Weight Quantity Unit.quote.price Total.quote.price Material.cost
1   1  SRA3    2      1        1         2.600000           2.60000       0.04104
2   2  SRA3    2      1        2         2.600000           5.20000       0.04104
3   3  SRA3    2      1        3         2.600000           7.80000       0.04104
4   4  SRA3    2      1        4         2.600000          10.40000       0.04104
5   5  SRA3    2      1        5         2.600000          13.00000       0.04104
6   6  SRA3    2      1        6         2.600000          15.60000       0.04104

但是当我尝试计算该数据集的分数时,它会输出错误的结果

> mean
                Type               Weight             Quantity     Unit.quote.price 
        1.454545e+00         3.636364e+00         2.500500e+03         7.815069e-01 
   Total.quote.price        Material.cost        Machine.price      Material.factor 
        1.538275e+03         8.483818e-02         1.545455e-01         4.900000e+01 
      Machine.factor Meter.reading.charge           Fix.charge             discount 
        5.890400e+00         7.727273e-02         7.727273e-02         1.542216e-01 
        Total.Profit          Unit.profit 
        9.396966e+02         5.421233e-01 
> sd <- apply(Pricing[,3:16],2,sd)
> sd
                Type               Weight             Quantity     Unit.quote.price 
        4.979341e-01         1.720096e+00         1.443389e+03         5.671822e-01 
   Total.quote.price        Material.cost        Machine.price      Material.factor 
        9.600757e+02         4.462600e-02         4.979341e-02         0.000000e+00 
      Machine.factor Meter.reading.charge           Fix.charge             discount 
        0.000000e+00         2.489671e-02         2.489671e-02         8.406364e-02 
        Total.Profit          Unit.profit 
        6.839202e+02         5.476514e-01

例如,对于“重量”列的第一行,zscore应该为

> zscore <- (Pricing[,3:16]-mean)/sd
> zscore
         Type     Weight    Quantity Unit.quote.price Total.quote.price Material.cost
1   1.0954352       -Inf   -1.731689      101.3277520         -1.599536    -1.3739256
2  -0.9513209 37.0622228    2.148327       29.0943682        114.622917    -0.9149677
3  -1.7309959 37.0622228   -1.599119       -1.3701840        153.543494    -2.8387399
4   2.1483273 10.0611683   87.732761        3.7576400              -Inf    -2.0901873
5  -1.6001606 -1.3725235   97.311156        2.3004138               Inf    -1.7323531

而不是'-Inf'。 请帮忙。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。