示例#1
0
func ExampleCorrelationCoefficient() {
	// Example 4.b, p. 40.
	data := []struct{ X, Y float64 }{
		{73, 90.4},
		{38, 125.3},
		{35, 161.8},
		{42, 143.4},
		{78, 52.5},
		{68, 50.8},
		{74, 71.5},
		{42, 152.8},
		{52, 131.3},
		{54, 98.5},
		{39, 144.8},

		{61, 78.1},
		{42, 89.5},
		{49, 63.9},
		{50, 112.1},
		{62, 82.0},
		{44, 119.8},
		{39, 161.2},
		{43, 208.4},
		{54, 111.6},
		{44, 167.1},
		{37, 162.1},
	}
	a, b := fit.Linear(data)
	fmt.Printf("y = %.2f - %.2fx\n", b, -a)
	fmt.Printf("r = %.3f\n", fit.CorrelationCoefficient(data))
	// Output:
	// y = 244.18 - 2.49x
	// r = -0.767
}
示例#2
0
func ExampleLinear() {
	// Example 4.a, p. 37.
	a, b := fit.Linear([]struct{ X, Y float64 }{
		{.2982, 10.92},
		{.2969, 11.01},
		{.2918, 10.99},
		{.2905, 10.78},
		{.2707, 10.87},

		{.2574, 10.80},
		{.2485, 10.75},
		{.2287, 10.14},

		{.2238, 10.21},
		{.2156, 9.97},
		{.1992, 9.69},

		{.1948, 9.57},
		{.1931, 9.66},
		{.1889, 9.63},
		{.1781, 9.65},
		{.1772, 9.44},
		{.1770, 9.44},

		{.1755, 9.32},
		{.1746, 9.20},
	})
	fmt.Printf("a = %.2f  b = %.2f\n", a, b)
	fmt.Printf("m = %.2f + 5 logΔ  + %.2f log r\n", b, a)
	// Output:
	// a = 13.67  b = 7.03
	// m = 7.03 + 5 logΔ  + 13.67 log r
}