> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ttest

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/4/fusion-server/reference/fusion-sql/ttest

[mintlify link]: https://doc.lucidworks.com/docs/4/fusion-server/reference/fusion-sql/ttest

[old doc.lw link]: https://doc.lucidworks.com/fusion-server/4.2/3259

The `ttest` function performs a two sided t-test on two random samples drawn from two queries. The `ttest` function takes four parameters:

1. the numeric field on which to perform the t-test
2. the query for drawing the first sample
3. the query for drawing the second sample
4. the sample size for both samples

<LwTemplate />

## Sample syntax

```sql wrap  theme={"dark"}
select ttest(sepal_width_d, "species_s:versicolor", "species_s:virginica", 150) as t,
       p_value
from iris
```

## Result set

The result set for the ttest function contains one row with the results of the ttest. The ttest function returns the t statistic. The p\_value field can be selected to return the p-value for the ttest.

Sample result set in Apache Zeppelin:

<img src="https://mintcdn.com/lucidworks/aGMTh7KKUIwUyuv7/assets/images/5.2/udf/ttest1.png?fit=max&auto=format&n=aGMTh7KKUIwUyuv7&q=85&s=3fba983a407623301311e3e6968fc32a" alt="Sample result" width="1570" height="1122" data-path="assets/images/5.2/udf/ttest1.png" />

## Visualization

Sample visualization of the ttest function using the Apache Zeppelin number visualization:

<img src="https://mintcdn.com/lucidworks/aGMTh7KKUIwUyuv7/assets/images/5.2/udf/ttest2.png?fit=max&auto=format&n=aGMTh7KKUIwUyuv7&q=85&s=e13fd5a560556997d24ef4b8f31b5614" alt="Sample visualization" width="1568" height="1158" data-path="assets/images/5.2/udf/ttest2.png" />
